This module provides Get
values for parsing various
IP packets and headers from ByteStrings into a byte-sequence-independent
representation as Haskell datatypes.
Warning:
These are incomplete. The headers may not contain all the information that the protocols specify. For example, the Haskell representation of an IP Header only includes source and destination addresses and IP protocol number, even though an IP packet has many more header fields. More seriously, an IP header may have an optional extra headers section after the destination address. We assume this is not present. If it is present, then the transport protocol header will not be directly after the destination address, but will be after these options. Therefore functions that assume this, such as the getExactMatch function below, will give incorrect results when applied to such IP packets.
The Haskell representations of the headers for the transport protocols are similarly incomplete. Again, the Get instances for the transport protocols may not parse through the end of the transport protocol header.
- type IPPacket = IPHeader :*: (IPBody :*: HNil)
- data IPHeader = IPHeader {}
- type DifferentiatedServicesCodePoint = Word8
- type FragOffset = Word16
- type IPProtocol = Word8
- type IPTypeOfService = Word8
- type TransportPort = Word16
- ipTypeTcp, ipTypeIcmp, ipTypeUdp :: IPProtocol
- data IPBody
- fromTCPPacket :: IPBody -> Maybe (TCPHeader :*: HNil)
- fromUDPPacket :: IPBody -> Maybe (UDPHeader :*: (ByteString :*: HNil))
- withIPPacket :: HList l => (IPBody -> Maybe l) -> IPPacket -> Maybe (IPHeader :*: l)
- foldIPPacket :: (IPHeader -> IPBody -> a) -> IPPacket -> a
- foldIPBody :: (TCPHeader -> a) -> (UDPHeader -> a) -> (ICMPHeader -> a) -> (ByteString -> a) -> IPBody -> a
- getIPPacket :: Get IPPacket
- getIPPacket2 :: Get IPPacket
- getIPHeader :: Get IPHeader
- type ICMPHeader = (ICMPType, ICMPCode)
- type ICMPType = Word8
- type ICMPCode = Word8
- getICMPHeader :: Get ICMPHeader
- type TCPHeader = (TCPPortNumber, TCPPortNumber)
- type TCPPortNumber = Word16
- getTCPHeader :: Get TCPHeader
- type UDPHeader = (UDPPortNumber, UDPPortNumber)
- type UDPPortNumber = Word16
- getUDPHeader :: Get UDPHeader
IP Packet
An IP Header includes various information about the packet, including the type of payload it contains. Warning: this definition does not include every header field included in an IP packet.
IPHeader | |
|
type FragOffset = Word16Source
type IPProtocol = Word8Source
type IPTypeOfService = Word8Source
type TransportPort = Word16Source
The body of an IP packet can be either a TCP, UDP, ICMP or other packet.
Packets other than TCP, UDP, ICMP are represented as unparsed ByteString
values.
fromUDPPacket :: IPBody -> Maybe (UDPHeader :*: (ByteString :*: HNil))Source
foldIPPacket :: (IPHeader -> IPBody -> a) -> IPPacket -> aSource
foldIPBody :: (TCPHeader -> a) -> (UDPHeader -> a) -> (ICMPHeader -> a) -> (ByteString -> a) -> IPBody -> aSource
Parsers
type ICMPHeader = (ICMPType, ICMPCode)Source
type TCPHeader = (TCPPortNumber, TCPPortNumber)Source
type TCPPortNumber = Word16Source
type UDPHeader = (UDPPortNumber, UDPPortNumber)Source
type UDPPortNumber = Word16Source