Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Get host name from IP address
Hello guys,

I'm trying to write a simple function which would return the FQDN of a host
from its IPaddress :

int main( int argc, char *argv[] ) {

int   len;
char  answer[4096];

if( res_init( ) != 0 )
return -1;

len = res_query( argv[1], C_IN, T_A, answer, 4096 );
printf( "len = %d\nerr = %d\n", len, h_errno);

return 0;
}

But if argv[1] is an IP address, res_query returns -1 with h_errno = 1
(Operation not permitted).
If argv[1] is, say, www.yahoo.com, no errors occurs.

Any idea of what's wrong ?

Thanks

Christian



Report this thread to moderator Post Follow-up to this message
Old Post
Christian
12-28-04 02:12 PM


Re: Get host name from IP address
Christian wrote :

> But if argv[1] is an IP address, res_query returns -1 with h_errno = 1
> (Operation not permitted).

Why not use gethostbyname() ?

You'll get a hostent structure that will contain the host name.

--
DINH V. Hoa,

"tuning et dope, aucun rapport" -- b.


Report this thread to moderator Post Follow-up to this message
Old Post
DINH Viet Hoa
12-28-04 02:12 PM


Re: Get host name from IP address
"DINH Viet Hoa" <dinh.viet.hoa@free.fr> a écrit dans le message de
news:etPan.41d14058.34c9249f.3d6d@utopia...
> Christian wrote :
> 
>
> Why not use gethostbyname() ?
>
> You'll get a hostent structure that will contain the host name.
>
> --
> DINH V. Hoa,
>
> "tuning et dope, aucun rapport" -- b.
>

gethostbyname() with www.yahoo.fr gives :
h_name = www.euro.yahoo.akadns.net
h_aliases = www.yahoo.fr

but with 193.108.197.230, it gives :
h_name = 193.108.197.230

i want a function that would return h230.cornut.fr from 193.108.197.230.

Any other idea ?



Report this thread to moderator Post Follow-up to this message
Old Post
Christian
12-28-04 02:12 PM


Re: Get host name from IP address
Christian wrote:

> i want a function that would return h230.cornut.fr from 193.108.197.230.
>
> Any other idea ?

gethostbyaddr()

--
mail1dotstofanetdotdk

Report this thread to moderator Post Follow-up to this message
Old Post
Bjorn Reese
12-28-04 02:12 PM


Re: Get host name from IP address
"Bjorn Reese" <breese@see.signature> a écrit dans le message de
news:41d1512b$0$671$ba624c82@nntp02.dk.telia.net...
> Christian wrote:
> 
>
> gethostbyaddr()
>
> --
> mail1dotstofanetdotdk

That's exactly what I wanted !

Thanks to you Bjorn, and also Dinh



Report this thread to moderator Post Follow-up to this message
Old Post
Christian
12-28-04 02:12 PM


Re: Get host name from IP address
just use

int gethostname(char *name, size_t len);


use the header

#include <unistd.h>, for more information just search
in BEEJ's network programming


all the best


Report this thread to moderator Post Follow-up to this message
Old Post
surendran.d@gmail.com
12-30-04 01:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:34 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.