Friday, August 26, 2011

Resolving Remote Addresses : gethostbyname functions

The process of turning a name like into an IP number is quite complex. It involves a number of files in your local system's /etc directory, including files such as /etc/resolv.conf, /etc/hosts, and /etc/nsswitch.conf, to name a few of them. Depending upon how your local system is configured, other files and daemon processes might come into play as well. For example, after these files have been consulted, a name server can be queried, which itself can forward queries to other name servers. All of this complexity represents detail that you really don't want to think about when writing your application program. Fortunately, the application writer is able to play the part of an ostrich and stick his head in the sand. If the system is properly configured, a few system function calls will be all that is required on the part of the programmer. Covered next is a related set of functions, which hide this complexity of remote name lookups for you.

It will be assumed in all of my posts that you have a Linux system that is properly configured. Entire posts have been written on system and network administration. Consequently, the focus of this post is to teach you how to program with sockets, and not how to set up domains and name servers.

I will present gethostbyname here to get the remote address.

Sample code using the gethostbyname(3) Function

No comments:

Post a Comment