Using _XOPEN_SOURCE for UNIX 98 Compatibility

There are two versions of most sockets APIs. The base IBM® i API uses BSD 4.3 structures and syntax. The other uses syntax and structures compatible with BSD 4.4 and the UNIX® 98 programming interface specifications. You can select the UNIX 98 compatible interface by defining the _XOPEN_SOURCE macro to a value of 520 or greater.

When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, some sockets APIs are mapped to internal names, as shown in the following table:

Application not using C-based languages can use the internal names if necessary.

Using _XOPEN_SOURCE also changes some of the structures used by sockets to match BSD 4.4/UNIX 98 standards. The differences are summarized in the following table:

Usage Notes

  1. The struct sockaddr length field (sa_len and the address family specific equivalents: sun_len, sin_len, and sin6_len) 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 (like the local_address parameter on bind()) and will be properly set on output addresses (like the address parameter on accept()).

  2. The AF_UNIX_CCSID address sockaddr_unc has not been updated with a length field equivalent to sa_len. If you use sa_len to set a length on this address, it will be ignored on input addresses and set to zero on output addresses.

  3. The structure sockaddr_storage is used to declare storage for any address family address. This structure is large enough and aligned for any protocol-specific structure. It may then be cast as sockaddr structure for use on the APIs. The ss_family field of the sockaddr_storage will always align with the family field of any protocol-specific structure.

    Note: The storage allocated is larger than 255 bytes so it's size should not be used for sa_len. The actual protocol-specific structure size should be used instead.

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