SOCKET(3XNET) | X/Open Networking Services Library Functions | SOCKET(3XNET) |
socket - create an endpoint for communication
cc [ flag ... ] file ... -lxnet [ library ... ] #include <sys/socket.h> int socket(int domain, int type, int protocol);
The socket() function creates an unbound socket in a communications domain, and returns a file descriptor that can be used in later function calls that operate on sockets.
The <sys/socket.h> header defines at least the following values for the domain argument:
AF_UNIX
AF_INET
AF_INET6
The type argument specifies the socket type, which determines the semantics of communication over the socket. The socket types supported by the system are implementation-dependent. Possible socket types include:
SOCK_STREAM
SOCK_DGRAM
SOCK_SEQPACKET
If the protocol argument is non-zero, it must specify a protocol that is supported by the address family. The protocols supported by the system are implementation-dependent.
The process may need to have appropriate privileges to use the socket() function or to create some sockets.
The function takes the following arguments:
domain
type
protocol
The domain argument specifies the address family used in the communications domain. The address families supported by the system are implementation-dependent.
The documentation for specific address families specify which protocols each address family supports. The documentation for specific protocols specify which socket types each protocol supports.
The application can determine if an address family is supported by trying to create a socket with domain set to the protocol in question.
Upon successful completion, socket() returns a nonnegative integer, the socket file descriptor. Otherwise a value of -1 is returned and errno is set to indicate the error.
The socket() function will fail if:
EAFNOSUPPORT
EMFILE
ENFILE
EPROTONOSUPPORT
EPROTOTYPE
The socket() function may fail if:
EACCES
ENOBUFS
ENOMEM
ENOSR
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | Standard |
MT-Level | MT-Safe |
accept(3XNET), bind(3XNET), connect(3XNET), getsockname(3XNET), getsockopt(3XNET), listen(3XNET), recv(3XNET), recvfrom(3XNET), recvmsg(3XNET), send(3XNET), sendmsg(3XNET), setsockopt(3XNET), shutdown(3XNET), socketpair(3XNET), attributes(7), standards(7)
June 10, 2002 | OmniOS |