socket(2) DG/UX 5.4.2 socket(2)
NAME
socket - create an endpoint for communication
SYNOPSIS
#include <sys/socket.h>
int socket (af, type, protocol)
int af;
int type;
int protocol;
where:
af Protocol family (domain)
type Type of service desired
protocol Optional protocol id (usually 0)
DESCRIPTION
Socket creates an endpoint for communication and returns a descriptor
for the socket.
The af parameter specifies the domain in which the socket should be
created. The domain determines the semantics of the service provided
and affects what services are available. The domains available in
the system are configuration dependent. Domains are identified by
constants defined in sys/socket.h. All constants begin with AF;
examples are AFUNIX and AFINET. However, defining a domain in
sys/socket.h does not imply the domain is configured in the current
system.
The socket has the indicated type that specifies the semantics of
communication. Socket types are defined in sys/socket.h as constants
beginning with SOCK; examples are SOCKSTREAM and SOCKDGRAM.
A SOCKSTREAM type provides sequenced, reliable, two-way connection-
based byte streams with an out-of-band data transmission mechanism.
A SOCKDGRAM socket supports datagrams (connectionless, unreliable
messages of a small, fixed maximum length). SOCKRAW sockets provide
access to internal network interfaces. The type SOCKRAW is
available only to the superuser.
The protocol optionally specifies a particular protocol to be
assigned to the socket. If the user doesn't care which protocol in
the domain supplies the service, a protocol of zero can be given and
the domain will choose an appropriate protocol.
However, many protocols may exist and a user can specify a particular
protocol by giving the protocol identifier in this manner. The
protocol number to use depends on the communication domain in which
communication is to take place; see the related documentation for a
particular domain for more information about individual protocols.
Sockets of type SOCKSTREAM are full-duplex byte streams, similar to
pipes. A stream socket must be in a connected state before any data
may be sent or received on it. A connection to another socket is
Licensed material--property of copyright holder(s) 1
socket(2) DG/UX 5.4.2 socket(2)
created with a connect call. Once connected, data may be transferred
using read and write calls or some variant of the send and recv
calls. When a session has been completed, a close may be performed.
Out-of-band data may also be transmitted as described in send and
received as described in recv.
The communications protocols used to implement a SOCKSTREAM ensure
that data is not lost or duplicated. If a piece of data for which
the peer protocol has buffer space cannot be successfully transmitted
within a reasonable length of time, then the connection is considered
broken. Subsequent calls will return an error, -1. The specific
error code in global variable errno will be ETIMEDOUT. The protocols
optionally keep sockets warm by forcing transmissions roughly every
minute in the absence of other activity. An error is then indicated
if no response can be elicited on an otherwise idle connection for a
extended period (e.g., five minutes). A SIGPIPE signal is raised if
a process sends on a broken stream; this causes naive processes,
which do not handle the signal, to exit.
SOCKDGRAM and SOCKRAW sockets allow sending of datagrams to
correspondents named in send calls. You can also receive datagrams
at such a socket with recv. Connected SOCKDGRAM sockets can
communicate through the read and write system calls.
An fcntl call can be used to specify a process group to receive a
SIGURG signal when the out-of-band data arrives.
ACCESS CONTROL
The access depends on the domain and type of service requested, see
information about the individual domain for restrictions. However,
in general only superuser can use sockets of type SOCKRAW.
RETURN VALUE
The return value is a descriptor referencing the socket.
0..maxfd A file descriptor which references the created socket.
-1 An error occurred. errno is set to indicate the error.
DIAGNOSTICS
Errno may be set to one of the following error codes:
EAFNOSUPPORT The specified address family is not supported in
this version of the system.
EACCES Permission to create a socket of the specified
type and/or protocol is denied.
ESOCKTNOSUPPORT The specified socket type is not supported in
this address family.
EPROTONOSUPPORT The specified protocol is not supported.
ENFILE The per-system descriptor table is full.
Licensed material--property of copyright holder(s) 2
socket(2) DG/UX 5.4.2 socket(2)
ENOBUFS No buffer space is available. The socket cannot
be created.
EPROTOTYPE The protocol type doesn't supply the desired type
of service.
ENOSTR The system is out of STREAMS resources and could
not create the protocol stream.
SEE ALSO
accept(2), bind(2), connect(2), getsockname(2), getsockopt(2),
ioctl(2), listen(2), recv(2), select(2), send(2), shutdown(2),
socketpair(2), inet(3N), unixipc(6F).
Licensed material--property of copyright holder(s) 3