#include <sys/types.h> #include <sys/socket.h> int socket(int address_family, int type, int protocol)
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.
AF_INET | For interprocess communications between processes on the same system or different systems in the Internet domain using the Internet Protocol (IPv4). |
AF_INET6 | For interprocess communications between processes on the same system or different systems in the Internet domain using the Internet Protocol (IPv6 or IPv4). |
AF_NS | For interprocess communications between processes
on the same system or different systems in the domain defined by the Novell or
Xerox protocol definitions.
Note: The AF_NS address family is no longer supported as of V5R2. |
AF_UNIX | For interprocess communications between processes on the same system in the UNIX domain. |
AF_UNIX_CCSID | For interprocess communications between processes on the same system in the UNIX domain using the Qlg_Path_Name_T structure. |
AF_TELEPHONY | For interprocess communications between processes
on the same system in the telephony domain.
Note: The AF_TELEPHONY address family is no longer supported as of V5R3. |
SOCK_DGRAM | Indicates a datagram socket is desired. |
SOCK_SEQPACKET | Indicates a full-duplex sequenced packet socket is desired. Each input and output operation consists of exactly one record. |
SOCK_STREAM | Indicates a full-duplex stream socket is desired. |
SOCK_RAW | Indicates communication is directly to the network protocols. A process must have the appropriate privilege *ALLOBJ to use this type of socket. Used by users who want to access the lower-level protocols directly. |
0 | Indicates that the default protocol for the type selected is to be used. For example, IPPROTO_TCP is chosen for the protocol if the type was set to SOCK_STREAM and the address family is AF_INET. |
IPPROTO_IP | Equivalent to specifying the value zero (0). |
IPPROTO_TCP | Indicates that the TCP protocol is to be used. |
IPPROTO_UDP | Indicates that the UDP protocol is to be used. |
IPPROTO_RAW | Indicates that communications is to the IP layer. |
IPPROTO_ICMP | Indicates that the Internet Control Message Protocol (ICMP) is to be used. |
IPPROTO_ICMPV6 | Indicates that the Internet Control Message Protocol (ICMPv6) is to be used. |
TELPROTO_TEL | Equivalent to specifying the value zero (0). |
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.
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.
socket() returns an integer. Possible values are:
When socket() fails, errno can be set to one of the following:
[EACCES] | Permission denied.
Process does not have the appropriate privileges to create the socket with the specified type or protocol. |
[EAFNOSUPPORT] | The type of socket is not supported in this
protocol family. |
[EIO] | Input/output error. |
[EMFILE] | Too many descriptions for this process. |
[ENFILE] | Too many descriptions in system. |
[ENOBUFS] | There is not enough buffer space for the
requested operation. |
[EPROTOTYPE] | The socket type or protocols are not compatible.
|
[EPROTONOSUPPORT] | No protocol of the specified type and domain
exists. |
[ESOCKTNOSUPPORT] | The specified socket type is not supported. |
[EUNATCH] | The protocol required to support the specified
address family is not available at this time. |
[EUNKNOWN] | Unknown system state. |
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
CPFA081 E | Unable to set return value or error code. |
Supported Combinations of Types and Protocols for AF_INET | |
---|---|
Socket Type | Protocol |
STREAM | IPPROTO_TCP (see Usage note 5) |
DGRAM | IPPROTO_UDP |
RAW | IPPROTO_RAW, IPPROTO_ICMP, protocol_number, (see Usage note 6) |
Supported Combinations of Types and Protocols for AF_INET6 | |
---|---|
Socket Type | Protocol |
STREAM | IPPROTO_TCP |
DGRAM | IPPROTO_UDP |
RAW | IPPROTO_RAW, IPPROTO_ICMPV6, protocol_number, (see Usage note 6) |
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.
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.
Top | UNIX-Type APIs | APIs by category |