Hello guys
I use windows function getaddrinfo to get the IPv4 address of a host.
struct addrinfo * aiList = NULL;
struct addrinfo aiHints;
aiHints.ai_family = AF_INET;
int iResult = getaddrinfo( szHostName, NULL, &aiHints, &aiList );
const struct addrinfo * aiPtr = aiList;
while ( aiPtr != NULL )
{
const struct sockaddr * pSockAddr = aiPtr->ai_addr;
aiPtr = aiPtr->ai_next;
}
declaration for struct sockaddr is:
struct sockaddr {
ushort sa_family;
char sa_data[14];
};
The function succeed and the values of aiPtr->ai_addr->sa_data for localhost is as follows
{ 0, 0, 127, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
Why two leading zeros here?
May it be ai_addr is of type struct sockaddr_in and The two leading zeros is member sin_port of sockaddr_in?
struct sockaddr_in{
short sin_family;
unsigned short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
}
I'm confused. can any body clarify whats happening?
Thanks in advance
Edit: the original subject was this:
Question about struct addrinfo returned by getaddrino