summaryrefslogtreecommitdiff
path: root/dht/LLCSNAP.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2019-09-28 13:43:29 -0400
committerJoe Crayne <joe@jerkface.net>2020-01-01 19:27:53 -0500
commit11987749fc6e6d3e53ea737d46d5ab13a16faeb8 (patch)
tree5716463275c2d3e902889db619908ded2a73971c /dht/LLCSNAP.hs
parentadd2c76bced51fde5e9917e7449ef52be70faf87 (diff)
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
Diffstat (limited to 'dht/LLCSNAP.hs')
-rw-r--r--dht/LLCSNAP.hs49
1 files changed, 49 insertions, 0 deletions
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 @@
1module LLCSNAP where
2
3import Data.Bits
4import Data.Word
5
6import Net.PacketParsing
7
8
9-- 802.2 LLC Header : SNAP extension
10-- --------------------------------------------------------------------------
11-- DSAP : SSAP : Control : OUI : Protocol ID
12-- 1 octet : 1 octet : 1 or 2 octets : 3 octets : 2 octets
13
14data LLCSNAP = LLCSNAP
15 { dsap :: Word8
16 , ssap :: Word8
17 , control :: Word16 -- 1 or 2 bytes
18 , oui :: Word32 -- 3 bytes
19 , protoid :: Word16
20 }
21 deriving (Eq,Ord,Read,Show)
22
23instance Parse LLCSNAP where
24 parse = do
25 -- LLC
26 dsap <- word8
27 ssap <- word8
28 control <- fromIntegral <$> word8
29 -- Based on "Understanding Logical Link Control" at
30 -- https://www.cisco.com/c/en/us/support/docs/ibm-technologies/logical-link-control-llc/12247-45.html
31 --
32 -- Unless the low two bits are set, there's
33 -- another byte of the control field.
34 nr <- if 0x0003 == control .&. 0x0003
35 then return 0
36 else fromIntegral <$> word8
37 -- SNAP
38 ouilo <- fromIntegral <$> word16
39 ouihi <- fromIntegral <$> word8
40 protoid <- word16
41 return LLCSNAP
42 { dsap = dsap
43 , ssap = ssap
44 , control = control + 256 * nr
45 , oui = ouilo + 65536 * ouihi
46 , protoid = protoid
47 }
48
49