With the AF_INET address family, a name comprises a 4-byte Internet address and a port number. You use the sockaddr_in address structure for the AF_INET address family. This structure has a variant for #define SIN_LEN.
The sockaddr_in structure is declared in the <netinet.in.h> header as follows:
struct sockaddr_in { short sin_family; /* address family AF_INET */ u_short sin_port; /* 16-bit port number */ struct in_addr sin_addr; /* 32-bit Internet address */ char sin_zero[8]; };
Structure variant of sockaddr_in with #define SIN_LEN set to support BSD 4.4 systems:
struct sockaddr_in { u_char sin_len; /* structure length */ u_char sin_family; /* address family AF_INET */ u_short sin_port; /* 16 bit port number */ struct in_addr sin_addr; /* 32 bit Internet address */ char sin_zero[8]; };
You can supply a variable server of type struct sockaddr_in with a name by using the following statements:
struct sockaddr_in server; ... server.sin_family = AF_INET; server.sin_port = htons(8888); server.sin_addr.s_addr = htonl(INADDR_ANY);
A pointer to the variable server can now be passed as the current parameter, e.g. with a bind() call, to bind the name to a socket:
bind(..., &server, ...) /* bind() call with type conversion */
The structures for host, protocol and service names are described in the chapter “Address conversion with SOCKETS(BS2000)”.