Creates an end point for communication and returns a descriptor.
Standard C Library (libc.a)
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.
|AddressFamily||Specifies an address family with which addresses specified in later socket operations should be interpreted. The /usr/include/sys/socket.h file contains the definitions of the address families. Commonly used families are:|
|Type||Specifies the semantics of communication. The
/usr/include/sys/socket.h file defines the socket types.
The operating system supports the following types:
|Protocol||Specifies a particular protocol to be used with the socket. Specifying the Protocol parameter of 0 causes the socket subroutine to default to the typical protocol for the requested type of returned socket.|
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:
|EAFNOSUPPORT||The addresses in the specified address family cannot be used with this socket.|
|ESOCKTNOSUPPORT||The socket in the specified address family is not supported.|
|EMFILE||The per-process descriptor table is full.|
|ENOBUFS||Insufficient resources were available in the system to complete the call.|
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.