Syntax
#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.
Parameters
| Note: | The OS/400 implementation only supports the Novell protocols. |
| Note: | The OS/400 implementation supports communication over ISDN telephone networks only. |
| Note: | You must explicitly specify the protocol to be used when the address family is AF_NS. |
| 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. |
Return Value
socket() returns an integer. Possible values are:
Error Conditions
When socket() fails, errno can be set to one of the following:
Process does not have the appropriate privileges to create the socket with the specified type or protocol.
Error Messages
Figure 1-18. Supported Combinations of Types and Protocols for AF_NS
| Socket Type | Protocol |
|---|---|
| SEQPACKET | NNSPROTO_SPX |
| STREAM | NNSPROTO_SPX |
| DGRAM | NNSPROTO_IPX |
Figure 1-19. 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) |
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 an SNA or IPX 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 or IPX, 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.
Related Information
socketpair()--Create a Pair of Sockets
| Top | Sockets APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |