Networking Forums

Networking Forums > Computer Networking > Linux Networking > regarding getaddrinfo and getnameinfo

Reply
Thread Tools Display Modes

regarding getaddrinfo and getnameinfo

 
 
amitkeerti
Guest
Posts: n/a

 
      08-04-2007, 05:54 AM
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 <<hostname;



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?

 
Reply With Quote
 
 
 
 
Agricolae Maximus
Guest
Posts: n/a

 
      08-05-2007, 04:16 AM
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
 
Reply With Quote
 
amitkeerti
Guest
Posts: n/a

 
      08-05-2007, 08:03 AM
On Aug 5, 9:16 am, Agricolae Maximus <a...@mail15.com> 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?

 
Reply With Quote
 
Unruh
Guest
Posts: n/a

 
      08-05-2007, 06:35 PM
amitkeerti <(E-Mail Removed)> writes:

>On Aug 5, 9:16 am, Agricolae Maximus <a...@mail15.com> 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 With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is getaddrinfo memory leak? step Linux Networking 2 07-12-2007 06:31 AM
getnameinfo() and localhost dkishenko@gmail.com Windows Networking 0 10-25-2006 07:54 AM
Why does getaddrinfo return only one address? David Linux Networking 1 12-19-2003 08:50 AM
getnameinfo() errors Gisle Vanem Linux Networking 1 11-18-2003 09:50 PM
getaddrinfo() Frank A. Uepping Linux Networking 0 10-16-2003 05:33 PM



1 2 3 4 5 6 7 8 9 10 11