I use gethostbyaddr and get a given hostname.
When i give the same host name while using gethostbyname i get a different ip address.
What could be the reason, is it fetching different address because of multi homed interface system or it has to anything with DNS configuration.
The code i used is as follows :
GETHOSTBYADDR --------------
#include<stdio.h> #include<sys/socket.h> #include<netdb.h> int main(int argc,char *argv[]) { struct hostent *host;
unsigned long adr; if (((int)adr = inet_addr(argv[1])) == -1) { printf("\n incorrect format of ip address"); } if((host = gethostbyaddr((char *)&adr,15,AF_INET)) != NULL) { printf("\n address %s",host->h_addr_list[0]); printf("\n address type %d",host->h_addrtype); printf("\n address length %d",host->h_length); printf("\n name %s",host->h_name); } herror(""); }
GETHOSTBYNAME ------------- #include<stdio.h> #include<sys/socket.h> #include<netdb.h> int main(int argc,char *argv[]) { struct hostent *host; if((host = gethostbyname(argv[1])) != NULL) { printf("\n address %s",inet_ntoa(host->h_addr_list[0])); printf("\n address type %d",host->h_addrtype); printf("\n address length %d",host->h_length); } herror(""); }
Thanks, Sudharsan.
ARISE, AWAKE AND STOP NOT TILL THE GOAL IS REACHED ___________________________________________________ Meet your old school or college friends from 1 Million + database... Click here to reunite www.batchmates.com/rediff.asp
- : send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html