ICMP

class os_ken.lib.packet.icmp.TimeExceeded(data_len=0, data=None)

ICMP sub encoder/decoder class for Time Exceeded Message.

This is used with os_ken.lib.packet.icmp.icmp for ICMP Time Exceeded Message.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

[RFC4884] introduced 8-bit data length attribute.

Attribute

Description

data_len

data length

data

Internet Header + leading octets of original datagram

class os_ken.lib.packet.icmp.dest_unreach(data_len=0, mtu=0, data=None)

ICMP sub encoder/decoder class for Destination Unreachable Message.

This is used with os_ken.lib.packet.icmp.icmp for ICMP Destination Unreachable Message.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

[RFC1191] reserves bits for the "Next-Hop MTU" field. [RFC4884] introduced 8-bit data length attribute.

Attribute

Description

data_len

data length

mtu

Next-Hop MTU

NOTE: This field is required when icmp code is 4

code 4 = fragmentation needed and DF set

data

Internet Header + leading octets of original datagram

class os_ken.lib.packet.icmp.echo(id_=0, seq=0, data=None)

ICMP sub encoder/decoder class for Echo and Echo Reply messages.

This is used with os_ken.lib.packet.icmp.icmp for ICMP Echo and Echo Reply messages.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

Attribute

Description

id

Identifier

seq

Sequence Number

data

Internet Header + 64 bits of Original Data Datagram

class os_ken.lib.packet.icmp.icmp(type_=8, code=0, csum=0, data=b'')

ICMP (RFC 792) header encoder/decoder class.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

Attribute

Description

type

Type

code

Code

csum

CheckSum (0 means automatically-calculate when encoding)

data

Payload. Either a bytearray, or os_ken.lib.packet.icmp.echo or os_ken.lib.packet.icmp.dest_unreach or os_ken.lib.packet.icmp.TimeExceeded object NOTE for icmp.echo: This includes "unused" 16 bits and the following "Internet Header + 64 bits of Original Data Datagram" of the ICMP header. NOTE for icmp.dest_unreach and icmp.TimeExceeded: This includes "unused" 8 or 24 bits and the following "Internet Header + leading octets of original datagram" of the original packet.

classmethod parser(buf)

Decode a protocol header.

This method is used only when decoding a packet.

Decode a protocol header at offset 0 in bytearray buf. Returns the following three objects.

  • An object to describe the decoded header.

  • A packet_base.PacketBase subclass appropriate for the rest of the packet. None when the rest of the packet should be considered as raw payload.

  • The rest of packet.

serialize(payload, prev)

Encode a protocol header.

This method is used only when encoding a packet.

Encode a protocol header. Returns a bytearray which contains the header.

payload is the rest of the packet which will immediately follow this header.

prev is a packet_base.PacketBase subclass for the outer protocol header. prev is None if the current header is the outer-most. For example, prev is ipv4 or ipv6 for tcp.serialize.