kazu-yamamoto / iproute

IP Routing Table in Haskell
http://www.mew.org/~kazu/proj/iproute/
BSD 3-Clause "New" or "Revised" License
47 stars 28 forks source link

Integer <-> IPv4 #23

Closed AlexeyRaga closed 9 years ago

AlexeyRaga commented 9 years ago

Given:

21548033 is 1.72.204.1

Test:

λ: fromHostAddress 21548033 :: IPv4
1.204.72.1

λ: toHostAddress (read "1.72.204.1" :: IPv4)
30164993

Could you please explain why octets are reversed? Or am I using fromHostAddress and toHostAddress incorrectly to convert from/to integers?

kazu-yamamoto commented 9 years ago

This is not Integer. That is HostAddress defined in http://hackage.haskell.org/package/network-2.6.2.1/docs/Network-Socket-Internal.html#t:HostAddress

Unfortunately, HostAddress is not in the host byte order but in the network byte order (big endian). (This is a dark side of the "network" library.) So, it is reversed on a littel endian machine.