This preview shows page 1. Sign up to view the full content.
Unformatted text preview: f host */ char **h_aliases; /* null-terminated array of domain names */ int h_addrtype; /* host address type (AF_INET) */ int h_length; /* length of an address, in bytes */ char **h_addr_list; /* null-terminated array of in_addr structs */ }; netdb.h Figure 12.11: DNS host entry structure. Internet applications retrieve arbitrary host entries from the DNS database by calling the gethostbyname and gethostbyaddr functions. 616
#include <netdb.h> CHAPTER 12. NETWORK PROGRAMMING struct hostent *gethostbyname(const char *name);
returns: non-NULL pointer if OK, NULL pointer on error with h errno set struct hostent *gethostbyaddr(const char *addr, int len, 0);
returns: non-NULL pointer if OK, NULL pointer on error with h errno set The gethostbyname returns the host entry associated with the domain name name. The gethostbyaddr function returns the host entry associated with the IP address addr. The second argument gives the length in bytes of an IP address, which for the current Internet is always four bytes. For our purposes, the third argument is always zero. We can explore so...
View Full Document
- Spring '10
- The American