What is and what is the structure sockaddr_in?

4

Lately I've been wanting to program a network sockets in C ++, but since the materials on the internet are a bit limited, I only show how to program the sockets without explaining in more detail the use of each function. I ended up getting lost a bit and some of the things that left me in doubt was the use of the structure "sockaddr_in". So what is and what is the structure of sockaddr_in?

    
asked by anonymous 26.09.2017 / 23:51

1 answer

4

In short, this structure deals with network addresses.

struct sockaddr_in {
    short            sin_family;
    unsigned short   sin_port;
    struct in_addr   sin_addr;
    char             sin_zero[8];
};

This in particular is the structure used with IPv4 addresses, for example 192.168.123.123.

In addition to this structure there are several other basic structures for all systems and functions that deal with Internet addresses. Many times you'll use getaddrinfo () to fill in those structures and then read them when you need them .

    
27.09.2017 / 10:06