socket(2)
_________________________________________________________________
socket System Call
Create an endpoint for communication.
_________________________________________________________________
SYNTAX
#include <socket.h>
int socket (af, type, protocol)
int af;
int type;
int protocol;
PARAMETERS
af Protocol Family (i.e., 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 <user/socket.h>.
All constants begin PF_; examples are PF_UNIX and PF_INET.
However, defining a domain in <user/socket.h> doesn't 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 <user/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
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
socket(2)
interfaces. The type SOCK_RAW 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 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 superuser can use sockets of type
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)
socket(2)
SOCK_RAW.
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.
EXCEPTIONS
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.
ENOBUFS No buffer space is available. The socket cannot
be created.
EPROTOTYPE The protocol type doesn't supply the desired type
of service.
SEE ALSO
DG/UX 4.00 Page 3
Licensed material--property of copyright holder(s)
socket(2)
The related manual sections: inet(3N), inet(6F), unix_ipc(6F),
udp(6), tcp(6), accept(2), bind(2), connect(2), getsockname(2),
getsockopt(2), ioctl(2), listen(2), recv(2), select(2), send(2),
shutdown(2), socketpair(2).
DG/UX 4.00 Page 4
Licensed material--property of copyright holder(s)