Socket address structure

Sockets use the sockaddr address structure to pass and to receive addresses. This structure does not require the socket API to recognize the addressing format.

Currently i5/OS™ supports Berkeley Software Distribution (BSD) 4.3 and X/Open Single Unix Specification (UNIX® 98). The base i5/OS 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.

Table 1. Comparison of BSD 4.3 and BSD 4.4/ UNIX 98 socket address structure
BSD 4.3 structure BSD 4.4/ UNIX 98 compatible structure
struct sockaddr{
  u_short   sa_family;
  char      sa_data [14];
};
struct sockaddr_storage{
  sa_family_t  ss_family;
  char         _ss_pad1[_SS_PAD1SIZE];
  char*        _ss_align;
  char         _ss_pad2[_SS_PAD2SIZE];
};
struct sockaddr {
  uint8_t       sa_len;
  sa_family_t   sa_family
  char          sa_data[14]
};
struct sockaddr_storage {
  uint8_t       ss_len;
  sa_family_t   ss_family;
  char          _ss_pad1[_SS_PAD1SIZE];
  char*         _ss_align;
  char          _ss_pad2[_SS_PAD2SIZE];
};
Table 2. Address 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 only provided for BSD 4.4 compatibility. It is not necessary to use this field even when using 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 fourteen 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 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.