Library /sys$common/syshlp/HELPLIB.HLB  —  TCPIP Services, Programming Interfaces, Socket API Functions, socket()
    Creates an endpoint for communication by returning a special
    kind of file descriptor called a socket descriptor, which is
    associated with a TCP/IP Services socket device channel.
    The $QIO equivalent is the IO$_SETMODE function.
    Format
      #include  <types.h>
      #include  <socket.h>
      int socket  ( int af, int type, int protocol );

1  –  Arguments

 af
    The address family used in later references to the socket.
    Addresses specified in subsequent operations using the socket are
    interpreted according to this family. Use one of the following:
    o  AF_INET for the IPv4 address family
    o  AF_INET6 for the IPv6 address family
    o  TCPIP$C_AUXS
       For a network application server with the LISTEN flag enabled,
       you specify the TCPIP$C_AUXS address family to obtain the
       connected device socket created by the auxiliary server in
       response to incoming network traffic.
 type
    The socket types are:
    o  SOCK_STREAM - Provides sequenced, reliable, two-way,
       connection-based byte streams with an available out-of-band
       data transmission mechanism.
    o  SOCK_DGRAM - Provides datagram transmissions. A datagram is a
       connectionless, unreliable data transmission mechanism.
    o  SOCK_RAW - Provides access to internal network interfaces.
       Available only to users with the SYSPRV privilege.
 protocol
    The protocol to be used with the socket. Normally, only a single
    protocol exists to support a particular socket type using a given
    address format. However, if many protocols exist, a particular
    protocol must be specified with this argument. Use the protocol
    number that is specific to the address family.

2  –  Description

    This function provides the primary mechanism for creating
    sockets. The type and protocol of the socket affect the way the
    socket behaves and how it can be used.
    The operation of sockets is controlled by socket-level options,
    which are defined in the SOCKET.H header file and described in
    the setsockopt() function section of this chapter.
    Use the setsockopt() and getsockopt()  functions to set and
    get options. Options take an integer argument that should be
    nonzero if the option is to be enabled or zero if it is to be
    disabled. SO_LINGER uses a linger structure argument (see linger
    Structure).
    Related Functions
    See also accept(), bind(),  connect(), getsockname(),
    getsockopt(), socketpair(),  listen(), read(), recv(),
    recvfrom(), recvmsg(),  select(), send(), sendmsg(),  sendto(),
    shutdown(), and write().

3  –  Return Values

    x                  A file descriptor that refers to the socket
                       descriptor.
    -1                 Error; errno is set to indicate the error.

4  –  Errors

    EACCES             The process does not have sufficient
                       privileges.
    EAFNOSUPPORT       The specified address family is not supported
                       in this version of the system.
    EMFILE             The per-process descriptor table is full.
    ENETDOWN           TCP/IP Services was not started.
    ENFILE             No more file descriptors are available for the
                       system.
    ENOBUFS            The system has insufficient resources to
                       complete the call.
    ENOMEM             The system was unable to allocate kernel
                       memory to increase the process descriptor
                       table.
    EPERM              The process is attempting to open a raw socket
                       and does not have SYSTEM privilege.
    EPROTONOSUPPORT    The socket in the specified address family is
                       not supported.
    EPROTOTYPE         The socket type is not supported by the
                       protocol.
    ESOCKTNOSUPPORT    The specified socket type is not supported in
                       this address family.
Close Help