Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageChristian 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.
Post Follow-up to this message"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 ?
Post Follow-up to this messageChristian wrote: > i want a function that would return h230.cornut.fr from 193.108.197.230. > > Any other idea ? gethostbyaddr() -- mail1dotstofanetdotdk
Post Follow-up to this message"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
Post Follow-up to this messagejust 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.