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 ("http://www.codeguru.com");
NetworkHostAddress = GetAddress ("63.236.73.79");

Downloads

Download demo project - 51 Kb
Download source - 2 Kb


Comments

  • URL Fix

    Posted by Legacy on 03/09/2003 12:00am

    Originally posted by: Jan Raddatz

    Hello,
    due to ISP trouble I had to move my website. I will publish the new URL to my source code as soon as possible here.


    Sorry for the blind links...
    Greetings
    Jan

    Reply
  • the file doesn't exist?

    Posted by Legacy on 11/16/2002 12:00am

    Originally posted by: Mauro Gagna

    Hey, i try to download the files and apparently the address is wrong.

    Where can i download this files?

    thanks

    Reply
  • WHERE ARE THE FILES

    Posted by Legacy on 09/28/2002 12:00am

    Originally posted by: mark Wall

    the server doesn't exist???

    Reply
  • Behind firewall ?

    Posted by Legacy on 10/11/2001 12:00am

    Originally posted by: William Rothwell

    In my company we are using a proxy to the Net, how can I make this program work please?

    Reply
  • Nice idea

    Posted by Legacy on 09/18/2001 12:00am

    Originally posted by: Jan Raddatz

    Hi fdr,
    nice idea to post the correct URL here.


    Sincerely
    Jan

    Reply
  • http://www.starbase1.de/Codeguru/inetaddrsource.zip

    Posted by Legacy on 09/12/2001 12:00am

    Originally posted by: fdr

    the right path is http://www.starbase1.de/Codeguru/inetaddrsource.zip

    Reply
  • Both downloads are the same

    Posted by Legacy on 09/05/2001 12:00am

    Originally posted by: SteveV

    Both the Demo download link and the Source download link point
    to the same demo download.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds