Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell network SockAddrInet which endianness to use?

Haskell networks HostAddress says "network byte order" in it's Documentation

However, if I pass address in network byte order(big-endian), it's show instance prints wrong address:

Prelude Network.Socket> :m + Network.Socket Data.Bits 
Prelude Network.Socket Data.Bits> SockAddrInet (fromInteger 50) (192 `shiftL` 24)
0.0.0.192:50
Prelude Network.Socket Data.Bits> 

Is this expected? Why it's printing things little-endian? Should I pass IP address in big or little endian format?

like image 854
sinan Avatar asked Nov 07 '14 14:11

sinan


1 Answers

It looks like the common way to generate IPv4 addresses is to use Socket.inet_addr, e.g.:

do x <- inet_addr "192.0.0.0"; return $ SockAddrInet 50 x

Or, equivalently:

inet_addr "192.0.0.0" >>= (return . SockAddrInet 50)
like image 116
ErikR Avatar answered Nov 16 '22 05:11

ErikR