socket()--Create Socket


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

  int socket(int address_family,
             int type,
             int protocol)

  Service Program Name: QSOSRV1

  Default Public Authority: *USE

  Threadsafe: Yes

The socket() function is used to create an end point for communications. The end point is represented by the socket descriptor returned by the socket() function.


Parameters

address_family
(Input) The address family to be used with the socket. Supported values are:
type
(Input) The type of communications desired. Supported values are:



protocol
(Input) The protocol to be used on the socket. Supported values are:



Note: When the type is SOCK_RAW, the protocol can be set to some predefined protocol number from 0-255. See Usage Notes for further details.


Authorities

When the SOCKET being created is of type SOCK_RAW, the thread must have *ALLOBJ special authority. When the thread does not have this authority, the EACCES is returned for errno.


Return Value

socket() returns an integer. Possible values are:


Error Conditions

When socket() fails, errno can be set to one of the following:



Error Messages



Usage Notes

  1. The socket address families and types supported by sockets are defined in <sys/socket.h>. The protocols are defined in <netinet/in.h> (Internet protocols).

  2. The AF_UNIX and AF_UNIX_CCSID address family supports a protocol of 0 for both SOCK_STREAM and SOCK_DGRAM.

  3. The AF_NS address family is no longer supported as of V5R2.

  4. The following tables list the combinations of types and protocols that are supported for AF_INET and the combinations of types and protocols that are supported for AF_INET6.





  5. The ALWANYNET (Allow ANYNET support) network attribute allows a customer to select whether a SNA transport can be used for AF_INET socket applications.

    The system administrator can see the current status of the ALWANYNET attribute and can change that status. (This can be done by using the Display Network Attributes (DSPNETA) and Change Network Attributes (CHGNETA) commands, respectively.)

    If the status is changed, the change takes effect immediately. Also, the state of the ALWANYNET stays the same across IPLs. For example, if the current status is *YES and the system administrator changes the value to *NO, the use of AF_INET over a transport other than TCP/IP is deactivated. If a system IPL is performed after this point, the use of AF_INET over a SNA transport remains deactivated after the system IPL.

    If AF_INET sockets will only be used over a TCP/IP transport, the ALWANYNET status should be set to *NO to improve CPU utilization.

    Note: If you are also using APPC over TCP/IP ALWANYNET status needs to be set to *YES.

  6. When the socket type is SOCK_RAW, you can specify any protocol number between 0-255. Two exceptions are the IPPROTO_TCP and IPPROTO_UDP protocols, which cannot be specified on a socket type of SOCK_RAW (if you issue socket(), you get an error with an error code of [EPROTONOSUPPORT]). Each raw socket is associated with one IP protocol number, and receives all data for that protocol. For example, if two processes create a raw socket with the same protocol number, and data is received for the protocol, then both processes get copies of the data.

    Protocol numbers 0 (IPPROTO_IP) and 255 (IPPROTO_RAW) have some unique characteristics. If a protocol number of zero is specified, then IP sends all data received from all the protocol numbers (except IPPROTO_TCP and IPPROTO_UDP protocols). If a protocol number of 255 is specified, a user must ensure that the IP header data is included in the data sent out on an output operation.

  7. The AF_TELEPHONY address family is no longer supported as of V5R3.

Related Information



API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]