The primitive for creating a socket is the
declared in sys/socket.h.
Preliminary: | MT-Safe | AS-Safe | AC-Safe fd | See POSIX Safety Concepts.
This function creates a socket and specifies communication style
style, which should be one of the socket styles listed in
Communication Styles. The namespace argument specifies
the namespace; it must be
PF_LOCAL (see Local Namespace) or
PF_INET (see Internet Namespace). protocol
designates the specific protocol (see Socket Concepts); zero is
usually right for protocol.
The return value from
socket is the file descriptor for the new
-1 in case of error. The following
conditions are defined for this function:
The protocol or style is not supported by the namespace specified.
The process already has too many file descriptors open.
The system already has too many file descriptors open.
The process does not have the privilege to create a socket of the specified style or protocol.
The system ran out of internal buffer space.
The file descriptor returned by the
socket function supports both
read and write operations. However, like pipes, sockets do not support file
For examples of how to call the
see Local Socket Example, or Inet Example.