socket(2) DG/UX R4.11MU05 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 AF_UNIX and AF_INET. 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 SOCK_STREAM and SOCK_DGRAM.
A SOCK_STREAM type provides sequenced, reliable, two-way connection-
based byte streams with an out-of-band data transmission mechanism.
A SOCK_DGRAM socket supports datagrams (connectionless, unreliable
messages of a small, fixed maximum length). SOCK_RAW sockets provide
access to internal network interfaces. The type SOCK_RAW is
available only to users with appropriate privilege (See ACCESS
CONTROL, below).
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 SOCK_STREAM 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
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 SOCK_STREAM 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.
SOCK_DGRAM and SOCK_RAW sockets allow sending of datagrams to
correspondents named in send calls. You can also receive datagrams
at such a socket with recv. Connected SOCK_DGRAM 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 users with appropriate privilege can use sockets of
type SOCK_RAW.
On a traditional DG/UX system, appropriate privilege is granted by
having an effective UID of 0 (root). See the
appropriate_privilege(5) man page for more information.
On a system with DG/UX information security, appropriate privilege is
granted by having one or more specific capabilities enabled in the
effective capability set of the user. See cap_defaults(5) for the
default capabilities for this command.
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.
EMFILE Too many descriptors are in use by this process.
ENOBUFS No buffer space is available. The socket cannot
be created.
EPROTOTYPE The protocol type doesn't supply the desired type
of service.
ENOSR 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), appropriate_privilege(5), unix_ipc(6F).
cap_defaults(5).
Licensed material--property of copyright holder(s)