regarding getaddrinfo and getnameinfo - Networking

This is a discussion on regarding getaddrinfo and getnameinfo - Networking ; hi, I was trying to get the corresponding hostname/canonical name for an IP address. I tried using both getaddrinfo and getnameinfo, but i am not getting proper results. For example getaddrinfo: Usage: hints.ai_socktype = 0; hints.ai_protocol = 0; hints.ai_flags = ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: regarding getaddrinfo and getnameinfo

  1. regarding getaddrinfo and getnameinfo

    hi,

    I was trying to get the corresponding hostname/canonical name for an
    IP address.
    I tried using both getaddrinfo and getnameinfo, but i am not getting
    proper results.

    For example
    getaddrinfo:
    Usage:
    hints.ai_socktype = 0;
    hints.ai_protocol = 0;
    hints.ai_flags = AI_CANONNAME;
    hints.ai_family = AF_INET;
    hints.ai_addrlen = 0;
    hints.ai_addr = 0;
    hints.ai_canonname = 0;

    if (error = getaddrinfo("203.200.202.207", NULL, &hints, &result))
    {
    cout <<"ERROR USING getaddrinfo \n";
    }


    Output:
    IP address 0 = 203.200.202.207 Canonical name 0 = 203.200.202.207
    You will see that canonical name is being shown same as that of IP
    address.




    Example: I tried getnameinfo:
    struct sockaddr_in a;
    int error=0;
    char hostname[NI_MAXHOST];

    memset((void*)&a, 0 , sizeof(a));
    a.sin_family = AF_INET;

    if(inet_aton("203.27.235.25",
    &(a.sin_addr)) == 0)
    {
    cout <<"inet_aton returned zero \n";
    return;
    }

    if((error = getnameinfo((struct sockaddr*)&a, sizeof(struct
    sockaddr),
    hostname, sizeof(hostname), NULL,0,0)))
    {

    cout <<"getnameinfo returned error \n";
    }

    cout <<"Hostname obtained is >> \n";
    cout <


    Observed Output is:
    Hostname obtained is >> 203.27.235.25

    Expected Output was:
    Hostname obtained is >> icicibank.com


    Can anyone tell me if my code is proper?
    If anyone has code for converting ip address to hostname, can you
    please forward me the code?


  2. Re: regarding getaddrinfo and getnameinfo

    On Fri, 03 Aug 2007 22:54:21 -0700, amitkeerti wrote:

    > hi,
    >
    > I was trying to get the corresponding hostname/canonical name for an
    > IP address.
    > I tried using both getaddrinfo and getnameinfo, but i am not getting
    > proper results.


    Try "whois"

    --
    Experience is that marvelous thing that enables you to
    recognize a mistake when you make it again.
    -- Anonymous
    ================================
    Registered Linux User No. 306834

  3. Re: regarding getaddrinfo and getnameinfo -- Urgent !

    On Aug 5, 9:16 am, Agricolae Maximus wrote:
    > On Fri, 03 Aug 2007 22:54:21 -0700, amitkeerti wrote:
    > > hi,

    >
    > > I was trying to get the corresponding hostname/canonical name for an
    > > IP address.
    > > I tried using both getaddrinfo and getnameinfo, but i am not getting
    > > proper results.

    >
    > Try "whois"
    >
    > --
    > Experience is that marvelous thing that enables you to
    > recognize a mistake when you make it again.
    > -- Anonymous
    > ================================
    > Registered Linux User No. 306834



    I am not looking at a command to do this.
    I am looking for code to do this. So API or sequence of APIs which
    will do this.
    I tried getnameinfo and getaddrinfo. Probably the way I am calling
    these 2 functions might be wrong...
    can anybody provide me the code?


  4. Re: regarding getaddrinfo and getnameinfo -- Urgent !

    amitkeerti writes:

    >On Aug 5, 9:16 am, Agricolae Maximus wrote:
    >> On Fri, 03 Aug 2007 22:54:21 -0700, amitkeerti wrote:
    >> > hi,

    >>
    >> > I was trying to get the corresponding hostname/canonical name for an
    >> > IP address.
    >> > I tried using both getaddrinfo and getnameinfo, but i am not getting
    >> > proper results.


    man getaddrinfo
    If you told us what you were getting we might be able to help. As it is,
    we are entirely in the dark.

    Ie show us your code fragment and what the output is.



    >>
    >> Try "whois"
    >>
    >> --
    >> Experience is that marvelous thing that enables you to
    >> recognize a mistake when you make it again.
    >> -- Anonymous
    >> ================================
    >> Registered Linux User No. 306834



    >I am not looking at a command to do this.
    >I am looking for code to do this. So API or sequence of APIs which
    >will do this.
    >I tried getnameinfo and getaddrinfo. Probably the way I am calling
    >these 2 functions might be wrong...
    >can anybody provide me the code?



+ Reply to Thread