module Network.Etherbunny.Packet (
Pkt,
wordsToInt,
wordsToWord16,
wordsToWord32
) where
import Data.Word
import Bits
wordsToInt :: Bits a => Int -> [Word8] -> a
wordsToInt i l =
let z5 = reverse [0..i1]
shifted = zipWith (\ b c -> (fromIntegral c) `shiftL` (b * 8) ) z5 l
in
foldr1 (.|.) shifted
wordsToWord16 :: [Word8] -> Word16
wordsToWord16 = wordsToInt 2
wordsToWord32 :: [Word8] -> Word32
wordsToWord32 = wordsToInt 4
class Pkt a where
headerLength :: a -> Int
instance Pkt Int where
headerLength = const 0