Socket address structure
Sockets use the sockaddr address structure to pass and receive addresses. This structure does not require the socket API to recognize the addressing format.
Currently, the IBM i operating system supports Berkeley Software Distribution (BSD) 4.3 and X/Open Single UNIX Specification (UNIX 98). The base IBM i API uses BSD 4.3 structures and syntax. You can select the UNIX 98 compatible interface by defining the _XOPEN_SOURCE macro to a value of 520 or greater. Each socket address structure for BSD 4.3 that is used has an equivalent UNIX 98 structure.
| BSD 4.3 structure | BSD 4.4/ UNIX 98 compatible structure |
|---|---|
|
|
| Address structure field | Definition |
|---|---|
| sa_len | This field contains the length of the address
for UNIX 98 specifications. Note: The sa_len field
is provided only for BSD 4.4 compatibility. It is not necessary to
use this field even for BSD 4.4/UNIX 98 compatibility. The field is
ignored on input addresses.
|
| sa_family | This field defines the address family. This value is specified for the address family on the socket() call. |
| sa_data | This field contains 14 bytes that are reserved
to hold the address itself. Note: The sa_data length of 14 bytes
is a placeholder for the address. The address can exceed this length.
The structure is generic because it does not define the format of
the address. The format of the address is defined by the type of transport,
which a socket is created for. Each of the transport providers define
the exact format for its specific addressing requirements in a similar
address structure. The transport is identified by the protocol parameter
values on the socket() API.
|
| sockaddr_storage | This field declares storage for any address family address. This structure is large enough and aligned for any protocol-specific structure. It can then be cast as sockaddr structure for use on the APIs. The ss_family field of the sockaddr_storage always aligns with the family field of any protocol-specific structure. |