gethostbyname query - TCP-IP

This is a discussion on gethostbyname query - TCP-IP ; Hi, I have a question pertaining to gethostbyname(). When I call gethostbyname("localhost"); does the query go to the DNS to resolve the IP for this host name or does it get from the /etc/resolv.conf. Basically I am looking for the ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: gethostbyname query

  1. gethostbyname query

    Hi,

    I have a question pertaining to gethostbyname().

    When I call gethostbyname("localhost"); does the query go to the DNS to
    resolve the
    IP for this host name or does it get from the /etc/resolv.conf.

    Basically I am looking for the implementation details of the
    gethostbyname().

    Thanks
    Kiran



  2. Re: gethostbyname query

    kiran shirol wrote:
    > I have a question pertaining to gethostbyname().


    You should be using getaddrinfo() these days

    > When I call gethostbyname("localhost"); does the query go to the DNS
    > to resolve the IP for this host name or does it get from the
    > /etc/resolv.conf.


    /etc/resolv.conf only lists things relating to reaching DNS servers,
    and a few options for DNS queries not the names one might try to
    resolve via same.

    > Basically I am looking for the implementation details of the
    > gethostbyname().


    For most Unix or Unix-like systems, the code called during
    gethostbyname() processing (or getaddrinfo()) will first check the
    contents of the "nsswitch.conf" file and decide which means, in which
    order should be used to try to resolve the name. So, where
    "localhost" is resolved will depend on system configuration.

    rick jones
    --
    oxymoron n, Hummer H2 with California Save Our Coasts and Oceans plates
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

  3. Re: gethostbyname query

    Thanks for the response.

    "Rick Jones" wrote in message
    news:g4j4t3$s99$1@usenet01.boi.hp.com...
    > kiran shirol wrote:
    >> I have a question pertaining to gethostbyname().

    >
    > You should be using getaddrinfo() these days
    >
    >> When I call gethostbyname("localhost"); does the query go to the DNS
    >> to resolve the IP for this host name or does it get from the
    >> /etc/resolv.conf.

    >
    > /etc/resolv.conf only lists things relating to reaching DNS servers,
    > and a few options for DNS queries not the names one might try to
    > resolve via same.
    >
    >> Basically I am looking for the implementation details of the
    >> gethostbyname().

    >
    > For most Unix or Unix-like systems, the code called during
    > gethostbyname() processing (or getaddrinfo()) will first check the
    > contents of the "nsswitch.conf" file and decide which means, in which
    > order should be used to try to resolve the name. So, where
    > "localhost" is resolved will depend on system configuration.
    >
    > rick jones
    > --
    > oxymoron n, Hummer H2 with California Save Our Coasts and Oceans plates
    > these opinions are mine, all mine; HP might not want them anyway...
    > feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...




  4. Re: gethostbyname query

    On Jul 3, 10:57 pm, "kiran shirol" wrote:
    > Hi,
    >
    > I have a question pertaining to gethostbyname().
    >
    > When I call gethostbyname("localhost"); does the query go to the DNS to
    > resolve the
    > IP for this host name or does it get from the /etc/resolv.conf.
    >
    > Basically I am looking for the implementation details of the
    > gethostbyname().
    >
    > Thanks
    > Kiran



    Hi Kiran,

    Typically it gets resolved without requesting the DNS server due to
    the following entry in /etc/hosts file as shown.

    [neo@techpulp ~] grep localhost /etc/hosts
    127.0.0.1 localhost.localdomain localhost localhost
    [neo@techpulp ~]


    - Neo
    Techpulp Technologies
    http://www.techpulp.com/

  5. Re: gethostbyname query

    On Thu, 3 Jul 2008 23:27:33 +0530, kiran shirol wrote:
    > Hi,
    >
    > I have a question pertaining to gethostbyname().
    >
    > When I call gethostbyname("localhost"); does the query go to the DNS to
    > resolve the
    > IP for this host name or does it get from the /etc/resolv.conf.
    >
    > Basically I am looking for the implementation details of the
    > gethostbyname().


    Most implementations are free, so you can have a look. One is here:

    http://www.freebsd.org/cgi/cvsweb.cg...ethostnamadr.c

    But I don't really think you want the "implementation details". You
    want to know if it's an interface to DNS or not, and that is more than
    just details. It's something you need to know to use it.

    /Jorgen

    --
    // Jorgen Grahn \X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!

+ Reply to Thread