I learn now about sockets and I saw that there is two struct
Sockaddr and sockaddrin.
The guide say to include char with 8 character in the struct to compare one struct to another I dont understand how its work can you explain me?
Its like cast int to char[2]?
How its working with structs?
Thank you.
SOCKADDR is a generic structure that contains an ADDRESS_FAMILY field and then 14 bytes (of type char) after that field. Depending on the value of the sin_family field (the ADDRESS_FAMILY), the 14 bytes that follow would be interpreted differently.
When the sin_family value equals AF_INET, then the SOCKADDR structure is really a SOCKADDR_IN structure, which just means that the 14 bytes really should be interpreted as:
2 bytes for sin_port
4 bytes for sin_addr
8 bytes of padding that aren’t used but have to be there to make it be the same size as a SOCKADDR structure.
So if you had a pointer to SOCKADDR, and you inspected the sin_family field and it equaled AF_INET, then you could cast your pointer to a pointer to SOCKADDR_IN and access the fields that way.