socket

Creates an endpoint for communication by returning a special kind of file descriptor called a socket descriptor, which is associated with a DEC TCP/IP Services for OpenVMS Socket Device Channel.

Format

#include  <socket.h>

int socket  (int af, int type, int
            protocol);

Arguments

af
The address format to be used in later references to the socket. Addresses specified in subsequent operations using the socket are interpreted according to this format. Currently, only AF_INET (Internet style) addresses are supported.
type
The semantics of communication. The type may be SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW.

SOCK_STREAM type sockets provide sequenced, reliable, two-way connection based byte streams with an available out-of-band data transmission mechanism.

SOCK_DGRAM sockets support datagrams (connectionless, unreliable data transmission mechanism).

SOCK_RAW sockets provide access to internal network interfaces, and are available only to users with SYSPRV privilege.

protocol
The protocol to be used with the socket. Normally only a single protocol exists to support a particular socket type using a given address format. However, it is possible that many protocols may exist, in which case a particular protocol must be specified with this argument. The protocol number to use is particular to the communication domain in which communication is to take place.

Description

This routine provides the primary mechanism for creating sockets. The type and protocol of the socket affect the way the socket behaves and how it can be used.

The operation of sockets is controlled by socket-level options, defined in the file <socket.h>. The setsockopt and getsockopt calls are used to set and get options. Options other than SO_LINGER take an integer parameter that should be nonzero if the option is to be enabled, or 0 if it is to be disabled. SO_LINGER uses a linger structure parameter defined in <socket.h>. The members of this structure specify the desired state of the option and the linger interval in the following manner:

SO_REUSEADDR indicates that the rules used in validating addresses supplied in a bind call should allow reuse of local addresses.

SO_KEEPALIVE keeps connections alive by enabling the periodic transmission of messages on a connected socket. Should the connected party fail to respond to these messages, the connection is considered broken and processes using the socket are notified through the error code SS$_LINKDISCON.

SO_DONTROUTE indicates that outgoing messages should bypass the standard routing facilities. Instead, messages are directed to the appropriate network interface according to the network portion of the destination address.

SO_LINGER lingers on close if data is present. It controls the actions taken when unsent messages are queued on the socket and a close is performed. When using the setsockopt to set the linger values, the option value for the SO_LINGER command is the address of a linger structure: ++++++++++++

     struct  linger {
             int     l_onoff;       /* option on/off */
             int     l_linger;      /* linger time */
     };

If the socket promises reliable delivery of data and l_onoff is nonzero, the system will block the process on the attempt until it is able to transmit the data or until it decides it is unable to deliver the information. A timeout period, called the linger interval, is specified in l_linger. If l_onoff is set to 0 and a close is issued, the system will process the close in a manner that allows the process to continue as quickly as possible.

SO_BROADCAST is used to enable or disable broadcasting on the socket.

See also accept, bind, connect, getsockname, getsockopt, listen, read, recv, recvfrom, recvmgs, select, send, sendmsg, sendto, shutdown, and write in this appendix.

Return Values
A file descriptor that refers to the socket descriptor. 
-1  Indicates an error; errno is set to one of the following:

  • EAFNOSUPPORT - The specified address family is not supported in this version of the system.

  • ESOCKTNOSUPPORT - The specified socket type is not supported in this address family.

  • EPROTONOSUPPORT - The specified protocol is not supported.

  • EPROTOTYPE - Request for a type of socket for which there is no supporting protocol.

  • EMFILE - The per-process descriptor table is full.

  • ENOBUFS - No buffer space is available. The socket cannot be created.
 


Previous Page | Next Page | Table of Contents | Index