Creates an end point for communication and returns a descriptor.
#include <sys/socket.h>
int socket ( AddressFamily, Type, Protocol)
int AddressFamily, Type, Protocol;
The socket subroutine creates a socket in the specified AddressFamily and of the specified type. A protocol can be specified or assigned by the system. If the protocol is left unspecified (a value of 0), the system selects an appropriate protocol from those protocols in the address family that can be used to support the requested socket type.
The socket subroutine returns a descriptor (an integer) that can be used in later subroutines that operate on sockets.
Socket level options control socket operations. The getsockopt and setsockopt subroutines are used to get and set these options, which are defined in the /usr/include/sys/socket.h file.
Upon successful completion, the socket subroutine returns an integer (the socket descriptor).
If the socket subroutine is unsuccessful, the subroutine handler performs the following functions:
The socket subroutine
is unsuccessful if any of the following errors occurs:
The following program fragment illustrates the use of the socket subroutine to create a datagram socket for on-machine use:
s = socket(AF_UNIX, SOCK_DGRAM,0);
The socket subroutine is part of Base Operating System (BOS) Runtime.
The socket applications can be compiled with COMPAT_43 defined. This will make the sockaddr structure BSD 4.3 compatible. For more details refer to socket.h.
The accept subroutine, bind subroutine, connect subroutine, getsockname subroutine, getsockopt subroutine, ioctl subroutine, listen subroutine, recv subroutine, recvfrom subroutine, recvmsg subroutine, select subroutine, send subroutine, sendmsg subroutine, sendto subroutine, setsockopt subroutine, shutdown subroutine, socketpair subroutine.
Initiating Internet Stream Connections Example Program, Sockets Overview, Understanding Socket Creation in AIX 5L Version 5.1 Communications Programming Concepts.