Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close(2)

fcntl(2)

ioctl(2)

read(2)

write(2)

accept(3N)

bind(3N)

connect(3N)

getsockname(3N)

getsockopt(3N)

listen(3N)

recv(3N)

send(3N)

shutdown(3N)

socketpair(3N)

netconfig(4)

socket(3N)                                                       socket(3N)

NAME
     socket - create an endpoint for communication

SYNOPSIS
     #include <sys/types.h>
     #include <sys/socket.h>

     int socket(int domain, int type, int protocol);

DESCRIPTION
     socket() creates an endpoint for communication and returns a descrip-
     tor.

     The domain parameter specifies a communications domain in which com-
     munication takes place. A communications domain is made up of address
     families and the corresponding protocol families. An address family
     groups together addresses with the same address structure. A protocol
     family defines a set of protocols which can be used by the socket
     types of an address family. Currently, the protocol family corresponds
     to the address family for the addresses which are used during subse-
     quent operations on the socket. These families are defined in the file
     /usr/include/sys/socket.h. The families currently used are:

     PFUNIX        UNIX system internal protocols

     PFINET        ARPA Internet protocols

     The socket has the indicated type, which specifies the communication
     method (connection-oriented or connectionless). Types defined and
     currently supported by Reliant UNIX are:

          SOCKSTREAM
          SOCKDGRAM
          SOCKRAW

     A SOCKSTREAM type provides sequenced, reliable, two-way connection-
     based byte streams. An out-of-band data transmission mechanism may be
     supported. 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 created with a connect(3N) call. Once connected, data may be trans-
     ferred using read(2) and write(2) calls or some variant of the
     send(3N) and recv(3N) calls. When a session has been completed, a
     close(2) may be performed. Out-of-band data may also be transmitted as
     described on the send(3N) manual page and received as described on the
     recv(3N) manual page.

     The communications protocols used to implement a SOCKSTREAM insure
     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 and calls will indicate an error with -1 returns and with



Page 1                       Reliant UNIX 5.44                Printed 11/98

socket(3N)                                                       socket(3N)

     ETIMEDOUT as the specific code in the global variable errno.

     The protocols have an optional mechanism for monitoring connections
     which are inactive for extended periods (i.e. if no data is transfer-
     red in this time), thus allowing such connections to be cleared. A
     mechanism of this type can be activated with the SOKEEPALIVE option
     and the setsockopt() call for the address family AFINET and the pro-
     tocol TCP. If the connection is inactive for too long (a global limit,
     usually 120 seconds), TCP sends periodic messages to the partner (typ-
     ically at intervals of 75 seconds). If the partner does not respond
     after a given number of repetitions, it is assumed that it is no
     longer live and the connection is cleared. 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.

     A SOCKDGRAM socket supports datagrams (connectionless, unreliable
     messages of a fixed (typically small) maximum length). SOCKRAW pro-
     vide access to internal network interfaces.

     SOCKDGRAM and SOCKRAW sockets allow datagrams to be sent to partners
     specified directly in sendto calls. Datagrams are received using
     recvfrom calls which return the next datagram and a source address.

     At least one entry must exist in the file /etc/netconfig for each pro-
     tocol family and each type.

     protocol specifies a particular protocol to be used with the socket.
     Normally only a single protocol exists to support a particular socket
     type within a given protocol family. However, multiple protocols may
     exist, in which case a particular protocol must be specified in this
     manner. The protocol number to use is particular to the "communication
     domain" in which communication is to take place. If a protocol is
     specified by the caller, then it will be packaged into a socket level
     option request and sent to the underlying protocol layers.

     If protocol was specified for the tuple family, type, protocol, but no
     corresponding entry was found in the file /etc/netconfig, the first
     entry is used which contains null for the specified family and type in
     the protocol entry.

     An fcntl(2) call can be used to specify a process group to receive a
     SIGURG signal when the out-of-band data arrives. It may also enable
     non-blocking I/O and asynchronous notification of I/O events with
     SIGIO signals.

     The operation of sockets is controlled by socket level options. These
     options are defined in the file /usr/include/sys/socket.h.
     setsockopt(3N) and getsockopt(3N) are used to set and get options,
     respectively.





Page 2                       Reliant UNIX 5.44                Printed 11/98

socket(3N)                                                       socket(3N)

RETURN VALUE
     A -1 is returned if an error occurs. Otherwise the return value is a
     descriptor referencing the socket.

DIAGNOSTICS
     The socket() call fails if:

     EPROTONOSUPPORT     The protocol type or the specified protocol is not
                         supported within this domain.

     EMFILE              The per-process descriptor table is full.

     EACCESS             Permission to create a socket of the specified
                         type and/or protocol is denied.

     ENOMEM              The user memory available is not sufficient.

     ENOSR               The STREAMS resources available were not suffi-
                         cient to complete the operation.

SEE ALSO
     close(2), fcntl(2), ioctl(2), read(2), write(2), accept(3N), bind(3N),
     connect(3N), getsockname(3N), getsockopt(3N), listen(3N), recv(3N),
     send(3N), shutdown(3N), socketpair(3N), netconfig(4).






























Page 3                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026