Quote Originally Posted by nkhambal
Not really, This is the man page definition of gethostbyaddr() on my linux PC,

Code:
struct hostent *gethostbyaddr(const char *addr, int len, int type);
Although as per OP, he is not passing char *, which I realized just now. The variable "addr" should be of type "char *" and NOT "unsigned long". My last post still stands correct about PTR record.

Function inet_ntoa() returns an ascii string containing the IP address in dotted decimal format as required by gethostbyaddr(). Perhaps, you should pay more attention to the complier warnings.
Notice what I wrote:

Quote Originally Posted by Dave Evans
The stuff pointed to by the first argument of gethostbyaddr is not a string, it is a struct in_addr (the four binary bytes of the ip address in network order for ipv4).
I chose my words carefully. I didn't say that the variable type of the argument has to be a pointer to a struct, I said that the stuff pointed to is a struct with the binary bytes. Note also, that I used a cast on the &iaddr to make sure the compiler didn't complain. I don't like to use casts just for the heck of it, and I could have made iaddr an array of four chars, thus eliminating compiler warning messages, but the way I did it will remind me what the argument really is on that day in the far future (like, maybe, next Tuesday) that I revisit this little example.

The man page shows function prototypes (and therefore the types of the arguments), but doesn't actually tell us anything about the nature of the the arguments to the functions. I don't just make this stuff up, you know. I looked here: Opengroup gethostbyaddr()

Where I found this:
The addr argument of gethostbyaddr() shall be an in_addr structure when type is AF_INET. It contains a binary format (that is, not null-terminated) address in network byte order.

I do not (and did not) dispute your claim about PTR. As a matter of fact, if I run the program on cisco.com, I get this:

domain: cisco.com ...

cisco.com 198.133.219.25 (www.cisco.com)
www.cisco.com 198.133.219.25 (www.cisco.com)
home.cisco.com 171.70.67.175 (wwwin-pool5.cisco.com)
ftp.cisco.com 198.133.219.27 (ftp-sj.cisco.com)
ns1.cisco.com 128.107.241.185 (ns1.cisco.com)
shop.cisco.com 198.133.219.23 (redirect.cisco.com)
secure.cisco.com 171.71.40.99 (secure.cisco.com)
forums.cisco.com 204.69.199.39 (forums.cisco.com)
beta.cisco.com 198.133.219.35 (beta.cisco.com)

complete ...
When I run it on hotmail.com, I get
domain: hotmail.com ...

hotmail.com 64.4.33.7 (hotmail.kz)
www.hotmail.com 66.35.214.30 (reverse lookup failed)
ns1.hotmail.com 216.200.206.140 (reverse lookup failed)

complete ...
Thus verifying your assertions, but also pointing out that the program (with my minor modification) works as desired.


Now the real reason for this post: When I tried it on my Linux box, it failed. The reason had nothing to do with the gethost... stuff, but because there is a bug in the wstrip() function in case the example.txt file was created by a text editor that has '\n' instead of '\r''\n' at the end of each line.

I fixed the wstrip function so that it works regardless of the end-of-line stuff and now everything works on Linux and Windows. (The OP didn't ask about wstrip(), and neither did anyone else, so I will refrain from submitting a solution for that little problem. If someone wants to start a new thread about wstrip(), OK. I really think this thread --- about the gethostbyaddr() --- should have been on the Networking forum anyhow.)



Regards,

Dave