Socket Address Data Structures

The socket data structure defines the socket. During a socket subroutine, the system dynamically creates the socket data structure.

The socket address is specified by a data structure that is defined in a header file. See the sockaddr Structure figure (Figure 1) for an illustration of this data structure.

Figure 1. sockaddr Structure
This diagram shows the sockaddr structure containing the following from the left: len, family, and socket address_data. The second line of the diagram gives the size of the sections in the first line as follows: len and family together equal 2 bytes, socket address_data is a variable size.

The /usr/include/sys/socket.h file contains the sockaddr structure. The contents of the sa_data structure depend on the protocol in use.

The types of socket-address data structures are as follows:
Item Description
struct sockaddr_in Defines sockets used for machine-to-machine communication across a network and interprocess communication (IPC). The /usr/include/netinet/in.h file contains the sockaddr_in structure.
struct sockaddr_un Defines UNIX domain sockets used for local IPC only. These sockets require complete path name specification and do not traverse networks. The /usr/include/sys/un.h file contains the sockaddr_un structure.
struct sockaddr_ndd Defines the operating system NDD sockets used for machine-to-machine communication across a physical network. The /usr/include/sys/ndd_var.h file contains the sockaddr_ndd structure. Depending upon socket types and protocol, other header files may need to be included.