How to resolve a name/IP ?

Discussion in 'C Programming' started by Doublehp, Jul 21, 2010.

  1. Doublehp

    Doublehp Guest

    Hello

    I would like to have the most simple, and shortest possible code to
    resolve a machine name, and get it's IP, possibly specifying the DNS I
    want to use.

    Just a function that will take as argument google.com, and return me
    66.249.92.104

    Thanks.
    Doublehp, Jul 21, 2010
    #1
    1. Advertising

  2. Doublehp

    Nobody Guest

    On Wed, 21 Jul 2010 14:09:20 -0700, Geoff wrote:

    >>I would like to have the most simple, and shortest possible code to
    >>resolve a machine name, and get it's IP, possibly specifying the DNS I
    >>want to use.


    > I believe you might be looking for the Berkeley Sockets
    > "gethostbyname" function.


    This has been superseded by getaddrinfo(), which has more features (e.g.
    the ability to return IPv6 addresses).

    > Getting it from a specific DNS server would involve more work.


    And is usually the wrong approach, as it bypasses any other name
    resolution methods (/etc/hosts, NIS, WINS, etc). Also, you shouldn't
    assume that you will be able to communicate directly with arbitrary DNS
    servers; it's fairly common for firewalls to block port 53 traffic for
    anything other than explicitly specified processes or hosts.
    Nobody, Jul 22, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    810
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,789
    ding feng
    Jun 25, 2003
  3. Replies:
    0
    Views:
    957
  4. Replies:
    1
    Views:
    10,109
  5. Bobby Chamness
    Replies:
    2
    Views:
    2,379
    Joe Smith
    Apr 22, 2007
Loading...

Share This Page