module Net.ARP where
import Net.Bits(Word8,Word16)
import Net.Ethernet as Eth(Addr)
import Net.IPv4 as IPv4(Addr)
import Net.PacketParsing
data Packet = Packet
{
opcode :: Operation,
senderHA :: Eth.Addr,
senderIP :: IPv4.Addr,
targetHA :: Eth.Addr,
targetIP :: IPv4.Addr }
deriving (Show)
data Operation = Request
| Reply
deriving (Eq,Show)
instance Parse Packet where
parse =
return Packet #! check16 0x0001 #! check16 0x0800
#! check8 0x06 #! check8 0x04
<# parse <# parse <# parse <# parse <# parse
#! therest
instance Unparse Packet where
unparse (Packet op sHA sIP tHA tIP) =
unparse (1::Word16,0x800::Word16,6::Word8,4::Word8) .
unparse (op,sHA,sIP,tHA,tIP)
instance Parse Operation where
parse = lift . conv =<< word16
where conv 1 = Just Request
conv 2 = Just Reply
conv w = Nothing
instance Unparse Operation where
unparse op = unparse (conv op)
where conv Request = 1::Word16
conv Reply = 2