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.
#include <socket.h> int socket (int af, int type, int protocol);
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.
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.
x | A file descriptor that refers to the socket descriptor. |
-1 | Indicates an error; errno is set to one of the following:
|