COHERENT manpages
This page displays the COHERENT manpage for socket() [Create a socket].
List of available manpages
Index
socket() -- Sockets Function (libsocket)
Create a socket
#include <sys/types.h>
#include <sys/socket.h>
int socket(domain, type, protocol)
int domain, type, protocol;
socket() creates a ``socket'' -- that is, an endpoint for communication.
It returns a descriptor that uniquely identifies the socket.
domain specifies the domain within which communication will take place.
This selects the protocol family to be used. These families are defined in
<sys/socket.h> Currently, socket() recognizes the following domains:
AF_UNIX UNIX internal protocols.
AF_INET ARPA Internet protocols.
The socket has the indicated type, which specifies the semantics of
communication. socket() recogizes the following types:
SOCK_STREAM
This type provides a byte stream that is sequenced, reliable,
two-way, and connection-based.
SOCK_DGRAM
This type supports ``datagrams'' -- that is, connectionless,
unreliable messages of a fixed maximum length.
protocol identifies the protocol to be used with the newly created socket.
In most instances, a given type of socket supports only one protocol.
However, a socket type may support many different protocols, in which case
you must specify the one to use. The protocol number to use is particular
to the ``communication domain'' in which communication is to take place.
Sockets of type SOCK_STREAM are full-duplex byte streams, similar to pipes.
A stream socket must be in a connected to another socket (through a call to
function connect()) before any data can be sent to it or received on it.
Once connected, data can be transferred using the system calls read() and
write(). When a session has been completed, invoke the system call close()
to close the socket.
If all goes well, socket() returns the descriptor of the newly created
socket; this is always a positive integer. If something goes wrong, it
returns -1 and sets errno to an appropriate value. The following lists the
possible errors, by the value to which socket() sets errno:
EPROTONOSUPPORT
type or protocol is not supported within this domain.
EMFILE
The per-process descriptor table is full.
ENFILE
The system file table is full.
EACCESS
You do not have permission to create a socket of a given type or
protocol.
ENOBUFS
Not enough buffer space is available. The socket cannot be created
until sufficient resources are freed.
See Also
accept(),
connect(),
libsocket,
listen(),
read(),
write()



