From 11987749fc6e6d3e53ea737d46d5ab13a16faeb8 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Sat, 28 Sep 2019 13:43:29 -0400 Subject: Factor out some new libraries word64-map: Data.Word64Map network-addr: Network.Address tox-crypto: Crypto.Tox lifted-concurrent: Control.Concurrent.Lifted.Instrument Control.Concurrent.Async.Lifted.Instrument psq-wrap: Data.Wrapper.PSQInt Data.Wrapper.PSQ minmax-psq: Data.MinMaxPSQ tasks: Control.Concurrent.Tasks kad: Network.Kademlia Network.Kademlia.Bootstrap Network.Kademlia.Routing Network.Kademlia.CommonAPI Network.Kademlia.Persistence Network.Kademlia.Search --- dht/LLCSNAP.hs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 dht/LLCSNAP.hs (limited to 'dht/LLCSNAP.hs') diff --git a/dht/LLCSNAP.hs b/dht/LLCSNAP.hs new file mode 100644 index 00000000..417c36ba --- /dev/null +++ b/dht/LLCSNAP.hs @@ -0,0 +1,49 @@ +module LLCSNAP where + +import Data.Bits +import Data.Word + +import Net.PacketParsing + + +-- 802.2 LLC Header : SNAP extension +-- -------------------------------------------------------------------------- +-- DSAP : SSAP : Control : OUI : Protocol ID +-- 1 octet : 1 octet : 1 or 2 octets : 3 octets : 2 octets + +data LLCSNAP = LLCSNAP + { dsap :: Word8 + , ssap :: Word8 + , control :: Word16 -- 1 or 2 bytes + , oui :: Word32 -- 3 bytes + , protoid :: Word16 + } + deriving (Eq,Ord,Read,Show) + +instance Parse LLCSNAP where + parse = do + -- LLC + dsap <- word8 + ssap <- word8 + control <- fromIntegral <$> word8 + -- Based on "Understanding Logical Link Control" at + -- https://www.cisco.com/c/en/us/support/docs/ibm-technologies/logical-link-control-llc/12247-45.html + -- + -- Unless the low two bits are set, there's + -- another byte of the control field. + nr <- if 0x0003 == control .&. 0x0003 + then return 0 + else fromIntegral <$> word8 + -- SNAP + ouilo <- fromIntegral <$> word16 + ouihi <- fromIntegral <$> word8 + protoid <- word16 + return LLCSNAP + { dsap = dsap + , ssap = ssap + , control = control + 256 * nr + , oui = ouilo + 65536 * ouihi + , protoid = protoid + } + + -- cgit v1.2.3