-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetwork.hs
More file actions
25 lines (19 loc) · 703 Bytes
/
Network.hs
File metadata and controls
25 lines (19 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Network where
import Control.Applicative (pure, (<$>), (<*>))
import Data.Binary
import Data.Binary.Get
import Data.ByteString.Lazy (ByteString, empty)
import Ethernet (EtherFrame(..), EtherType(..), fromEtherType)
import Datalink
import IP4
data Network = IP4 Packet
| UnsupportedNetwork !Integer ByteString
deriving (Show)
network :: Datalink -> Get Network
network (Ethernet frame) =
case _ethertype frame of
Ethernet.IP4 -> ip4
ftype -> UnsupportedNetwork <$> (pure . fromIntegral . fromEtherType) ftype <*> getRemainingLazyByteString
network UnsupportedDatalink{} = return $! UnsupportedNetwork 0 empty
ip4 :: Get Network
ip4 = Network.IP4 <$> get