This piece of code works OK on windows, but gethostbyaddr returns NULL on Linux.
I have tried so many changes, but without any success.
My /etc/host.conf has t
That host doesn't appear to have a reverse dns record registered.
$ dig -x 11.234.217.74
; <<>> DiG 9.9.1-P2 <<>> -x 11.234.217.74
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 30231
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;74.217.234.11.in-addr.arpa. IN PTR
;; AUTHORITY SECTION:
in-addr.arpa. 3599 IN SOA b.in-addr-servers.arpa. nstld.iana.org. 2011026180 1800 900 604800 3600
;; Query time: 1217 msec
So the call to gethostbyaddr
will fail. The herror
function will even print a message of Unknown host
. If you want to keep the numeric IP in those cases, you'll have to write that code path yourself. If Windows does anything else, it would be interesting to see where it got its information from.