Name and Address Conversions


The set of functions that an application calls to convert a hostname into an IP address and vice versa is called the resolver. The two functions gethostbyname and gethostbyaddr are the historical entry points. With the move to IPv6 and threaded programming models, the getaddrinfo and getnameinfo functions are more useful, with the ability to resolve IPv6 addresses and their thread-safe calling conventions.

The commonly used function dealing with service names and port numbers is getservbyname, which takes a service name and returns a structure containing the port number. This mapping is normally contained in a text file. Additional functions exist to map protocol names into protocol numbers and network names into network numbers, but these are rarely used.

Another alternative that we have not mentioned is calling the resolver functions directly, instead of using gethostbyname and gethostbyaddr. One program that invokes the DNS this way is sendmail, which searches for an MX record, something that the gethostby XXX functions cannot do. The resolver functions have names that begin with res_; the res_init function is an example. A description of these functions and an example program that calls them can be found in Chapter 15 of [Albitz and Liu 2001] and typing man resolver should display the man pages for these functions.

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows