Hello:
I am using gcc on RedHat Linux 9.
When I try to do a reverse dns query using gethostbyaddr, it works
fine for hosts that have a PTR record, but it returns null for hosts
that have a CNAME record. Any ideas how to work around this?
Here is an example:
dig -x 66.54.79.4
Gives me this answer:
4.79.54.66.in-addr.arpa. 35499 IN PTR
mail.JAMMConsulting.com.
And:
dig -x 64.61.26.100
Gives me this answer:
100.26.61.64.in-addr.arpa. 40544 IN CNAME 100.jfax.com.
I wrote this test program:
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
int main(argc, argv)
int argc;
char *argv[];
{
/* Perform the lookup */
/*unsigned long network_ip = htonl(0x42364f04); /* IP 66.54.79.4 */
unsigned long network_ip = htonl(0x403d1a64); /* IP 64.61.26.100 */
struct hostent *result;
result = gethostbyaddr((const void*)&network_ip, sizeof(unsigned
long), AF_INET);
if( result == NULL ) {
printf( "Hostentry is null\n" );
} else {
if( result->h_name == NULL ) {
printf( "Hostname is null\n" );
} else
printf( "Got back %s\n", result->h_name );
}
}
when I run it with the network ip for 66.54.79.4, I get back
mail.JAMMConsulting.com which is what I expected, but when I run it
with the network ip for 64.61.26.100, I get back a null result
pointer.
Any ideas how to work around this?
Thanks
Neil
--
Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
FREE! Valuable info on how your business can reduce operating costs by
17% or more in 6 months or less! =>
http://newsletter.JAMMConsulting.com