View Full Version : [solved] QHostAddress::toSring() backwards?

28th November 2007, 00:47
This is odd, to me at least.

I haver an integer that I convert to an IPv4 address using QHostAddress and setAddress(). (I pull the integers from /proc/net/tcp on Linux).

Yet when I use toString() I get the IP address backwards by octet. For examples: "" and "" :confused:
This is not what the docs say I should get ( and, respectively) . Anyone else see this, and of so, how does one (simply) go about getting it output correctly? I could, I suppose, use split() and reverse the list order. But *ugh*, that'd be a hack plain and simple (though that could be said f using QHostAddress to convert an int to an IP address in dotted notation :p )

28th November 2007, 00:53
You probably have a little-endian machine and you should pass the number in network order (or vice-versa), but you are probably passing the number in host order. Try using htonl() and passing the result to setAddress().

28th November 2007, 00:57
Ah thanks, that did it.

Looking back at the docs for setAddress, it says for the ip6Addr entry to set high-order byte first, but nothing for ip4Addr. Methinks they should copy that over. ;)

funny how a totally unexpected result can really toss your wits out the window. :)