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.
- data IPPacket = IPPacket IPHeader IPBody
- data IPHeader = IPHeader {}
- type DifferentiatedServicesCodePoint = Word8
- type FragOffset = Word16
- type IPProtocol = Word8
- type IPTypeOfService = Word8
- type TransportPort = Word16
- ipTypeTcp :: IPProtocol
- ipTypeUdp :: IPProtocol
- ipTypeIcmp :: IPProtocol
- data IPBody
- getIPPacket :: 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
- class FramedMessage m a b | m -> a, m -> b where
- body :: m -> b
- sourceAddress :: m -> a
- destAddress :: m -> a
IP Packet
An IP packet consists of a header and a body.
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.
Parsers
type ICMPHeader = (ICMPType, ICMPCode)Source
type TCPHeader = (TCPPortNumber, TCPPortNumber)Source
type TCPPortNumber = Word16Source
type UDPHeader = (UDPPortNumber, UDPPortNumber)Source
type UDPPortNumber = Word16Source
Framed Messages
class FramedMessage m a b | m -> a, m -> b whereSource
The FramedMessage
class defines the class of data types
which represents messages having source and destination addresses
and a message body.