Hi
Why do we use a sockaddr_in structure in order to get the ip address of any host whose ip information is retrieved with gethostbyname() and why can't we use h_addr_list elements directly!
For exmaple
Code:
// whis works
struct hostent *h;
struct sockaddr_in sa;
h = gethostbyname(hostname);
for (i=0; h->h_addr_list[i]; i++) {
memcpy ( &sa.sin_addr.s_addr, he.h_addr_list[nAdapter],he.h_length);
printf("Address: %s\n", inet_ntoa(sa.sin_addr));
}
// this fails!
struct hostent *h;
h = gethostbyname(hostname);
for (i=0; h->h_addr_list[i]; i++) {
printf("Address: %s\n", h->h_addr_list[i]);
}
the array elements in h_addr_list are *char. So, whay cannot we directly use those value?