#2795: The Network.Socket library does not take into account that the bits in
the
network are sent as big enddian.
-----------------------------------------------------------------------+----
Reporter: guest |
Owner:
Type: bug |
Status: new
Priority: normal |
Component: libraries/network
Version: |
Severity: major
Keywords: socket port number big-enddian little-enddian conflict |
Testcase:
Architecture: x86 |
Os: Linux
-----------------------------------------------------------------------+----
We got the program (1) below that is supposed to open a server in the
port 51777. However, when we run the program, we observed that the port
created was the number 16842. We believe that this difference comes from
the fact that we run the program in a little enddian machine (Intel
processor) and the socket library consider big enddian numbers instead. If
we take 51777 and converted as indicated by function conv (see (2)), the
socket open is indeed 51777.
Kind regards,
Alejandro Russo & Josef Svenningsson
(1)
import Network.Socket
import System
main = do s <- socket AF_INET Stream 0
arg <- getArgs
let shost = head arg
port = PortNum 51777
host <- inet_addr shost
putStrLn "Making the server..."
bindSocket s (SockAddrInet port host)
b <- sIsBound s
putStrLn "Socket bounded!"
listen s 5
putStrLn "Listening OK"
putStrLn "Waiting for clients..."
(s', c) <- accept s
putStrLn "Client found!"
str <- recv s' 255
putStr "Message received:"
putStr str
(2)
conv :: Word16 -> Word16
conv w16 = shiftL (fromIntegral a) 8 .|. fromIntegral b
where a = fromIntegral w16 :: Word8
b = fromIntegral (shiftR w16 8) :: Word8
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2795>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs