4 ms·
gethostbyname() and friends fill in struct hostent: struct hostent { char *h_name; /* official name of host */ char **h_aliases;
by zrm 12y ago
gethostbyname() and friends fill in struct hostent:
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
}
The pointers in the structure point into the buffer. There could be any number of host aliases or IP addresses.
- tptacek 12y agoThat's true and a good point, but not (it seems) applicable to this particular function, which validates whether or not the name is one of two fixed-sized formats, right? (edit) You may be totally right here, by the way.
- zrm 12y agoIt looks like what's going on is that gethostbyname() calls __nss_hostname_digits_dots() which checks to see if the string you passed it was an IPv4 or IPv6 address rather than a name, and in that case it functions like inet_aton/inet_pton and converts the IP address string to a binary IP address as though the "name" 1.2.3.4 resolved to IP address 1.2.3.4. In that specific case there are no aliases and exactly one IP address, but the buffer could still be too small (e.g. if caller-supplied with gethostbyname_r()).