struct sockaddr { unsigned short sa_family; // address family, AF_xxx char sa_data[14]; // 14 bytes of protocol address };
In this structure what exactly is the meaning address family depicted by sa_family
?
Does it mean that protocols like TCP/UDP have "addresses"? Well, the protocols can be identification numbers not addresses, I think.
Anyway, if yes, then on what basis have their families been divided?
sockaddr. The first structure is sockaddr that holds the socket information − struct sockaddr { unsigned short sa_family; char sa_data[14]; }; This is a generic socket address structure, which will be passed in most of the socket function calls.
The in_addr structure represents an IPv4 Internet address.
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.
sa_family. The address family for the transport address.
The format and size of the address is usually protocol specific.
sockaddr
is used as the base of a set of address structures that act like a discriminated union, see the Beej guide to networking. You generally look at the sa_family
and then cast to the appropriate address family's specific address structure.
TCP and UDP do not have addresses specific to them as such, rather the IP level has different sizes of address for IPv4 and IPv6.
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With