This structure references the socket's elements that are used for keeping addresses. The following are the built-in members of this structure:
struct sockaddr_in {
short int sin_family;
unsigned short int sin_port;
struct in_addr sin_addr;
unsigned char sin_zero[8];
};
Here, we have the following:
- sin_family: Represents an address family. The valid options are AF_INET, AF_UNIX, AF_NS, and AF_IMPLINK. In most applications, the address family that's used is AF_INET.
- sin_port: Represents the 16-bit service port number.
- sin_addr: Represents a 32-bit IP address.
- sin_zero: This is not used and is usually set to NULL.
struct in_addr comprise one member, as follows:
struct in_addr {
unsigned long s_addr;
};
Here, s_addr is used to represent the address in network byte order.