Hostname Resolving

Environment: VC6 SP4, NT4 SP3, Win 98, Win ME

Have you ever offered an edit control in your application in which the user had to enter an IP address or Hostname?

After the user entered the hostname or IP you have to check what was entered. (IP or hostname???) Then you have to convert the userinput into a proper address for the in_addr structure.

This is really annoying. I looked for a smother way. The function GetAddress (const char* p_pHost) is the result. You just hand over a string containing an IP or Hostname and GetAddress returns the proper address for the in_addr structure.

This function is useful for developers who directly access the Winsock API instead of using CAsyncSocket or CSocket. Or, if you wrote your own Socket class and want to offer a connect routine like in CAsyncSocket where you can enter either an IP or Hostname.

The demo project shows how to use GetAddress. It's a simple console based application. The function definition is as follows:

     unsigned long GetAddress (const char* p_pHost)

Below are a few examples showing how to use the function:

unsigned long NetworkHostAddress;
NetworkHostAddress = GetAddress ("");
NetworkHostAddress = GetAddress ("");


Download demo project - 51 Kb
Download source - 2 Kb