Most socket functions require a pointer to the socket address structure as a parameter. Each protocol cluster defines its own socket address structure
The names of these structures begin with sockaddr_ and end with a unique suffix corresponding to each protocol cluster
1.ipv4 Socket Address Structure
IPV4 socket address structure is commonly referred to as: Internetwork Socket address Structure
It is named after the sockaddr_in
struct in_addr{
in_addr_t s_addr;//32 bit unsigned integer type
};
struct sockaddr_in{
unit8_t sin_len;//socket Address structure length it is an unsigned short shape that can not set its value
sa_family_t the address family of the sin_family;//socket address structure any unsigned integer type
in_port_t sin_port;//tcp or UDP port number network byte order at least 16-bit unsigned integer type
struct IN_ADDR sin_addr;//ipv4 address network byte order
Cahr sin_zero[8];//not have to be aligned
};
2. Universal socket Address Structure
When passed into any socket function as a parameter, the socket address structure is always passed as a reference (that is, a pointer to the struct).
However, any socket function with such a pointer as one of the parameters must handle the socket address structure from any of the supported protocol families
With ANSI C The workaround is simple: void * is a generic pointer type
However the socket function is defined before ANSI C to take the method of defining a universal socket address structure
struct sockaddr{
uint8_t Sa_len;
sa_family_t sa_family;//Address Cluster type
Cahr sa_data[14];//
}
The socket function is then defined as one of its parameters as a pointer to a common socket address structure
Socket address Structure