in reply to Re^2: gethostbyname returns reverse order of ipaddress expected
in thread gethostbyname returns reverse order of ipaddress expected

Don't use pack, use inet_ntoa or whatever (same low level as gethostbyname, now lower like pack), common mistake

a gethostbyname , ?node_id=3989;HIT=gethostbyname;re=N
gethostbyname timing out or dns server can't find the host information
[id://869340|@addrs = (gethostbyname('www.yahoo.com'))4..-1 ?]
gethostbyname() problem
gethostbyname one-liner: Improvements?
gethostbyname("1.1.1") returns 1.1.0.1 ????
gethostbyname not working
gethostbyname bug?

  • Comment on Re^3: gethostbyname returns reverse order of ipaddress expected

Replies are listed 'Best First'.
Re^4: gethostbyname returns reverse order of ipaddress expected
by Anonymous Monk on Jun 25, 2013 at 22:20 UTC
    As I described in the 2 outputs, the C# one returns addresses in the correct order (increasing interface metric) while the perl one returns it in the reverse order (decreasing metric). It has nothing to do with the byte order of the individual ip address.

      all perl does is call the system gethostbyname and returns the results, it doesn't reorder them; if the results don't match whatever C# does, if it doesn't match your expectations, doesn't mean the results are wrong

        You are right. .NET gethostbyname actually calls getaddrinfo in some cases. getaddrinfo returns the addresses in "correct" order which gethostbyname does not on Windows. Hence the discrepancy. tried a native app which calls both and confirmed the difference. Thanks everyone.