What is the meaning of “sin_addr.s_addr ” and “inet_addr”?

sin_addr is the IP address in the socket (the socket structure also contains other data, such as a port). The type of sin_addr is a union, so it can be accessed in three different ways : as s_un_b (four 1-byte integers), s_un_w (two 2-bytes integers) or as s_addr (one 4-bytes integer).

inet_addr converts an IPv4 address from a string in dotted decimal representation to an integer. This function is deprecated because it does not support IPv6, use inet_pton instead.

So basically, the line about which you are asking loads into the socket the IP address 127.0.0.1, meaning the local host.

Leave a Comment