ICMP - Internet Control Message Protocol

pcapkit.protocols.internet.icmp contains ICMP only, which is a base class for Internet Control Message Protocol (ICMP) protocol family [*], e.g. ICMPv4 and ICMPv6. Constructing the base gives the one its version keyword names, from octets or from fields, and is refused without it, since an ICMP message carries no version of its own. Its from_data() gives the one whose data model it is handed (#2574).

class pcapkit.protocols.internet.icmp.ICMP[_PT: Data, _ST: Schema](file=None, length=None, **kwargs)[source]

Bases: Internet[_PT, _ST], Generic[_PT, _ST]

Abstract base class for ICMP protocol family.

It dispatches where the version is known, never giving an instance of this class (#2574). version names the member, from octets or from fields, and nothing else does: an ICMP message carries no version of its own, and no field picks a member, so either is refused without it. from_data() gives the member whose data model it is handed, and refuses a dict. See __new__().

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['ICMP'], Literal['ICMPv6']]

Returns:

Index ID of the protocol.

classmethod from_data(data, **kwargs)[source]

Create protocol instance from data.

Parameters:
Return type:

Self

Returns:

Protocol instance; on this class, an instance of the member whose data model data is.

Raises:

ProtocolError – If data is neither member’s data model, on this class. A dict is refused: it carries no version, and its keys need not tell the members apart, as an Echo message’s do not.

__init__(file=None, length=None, *, version=None, **kwargs)[source]

Initialisation.

Parameters:
  • file (IO[bytes] | bytes | None) – Source packet stream.

  • length (int | None) – Length of packet data.

  • version (Literal[4, 6] | None) – Version of ICMP, 4 or 6: the member __new__() picks. Building from fields, it must be this class’s own. Parsing, it is handed on unread, as the enclosing IP layer passes its own version under this name to the layer it carries.

  • **kwargs (Any) – As Protocol.__init__.

Raises:

ProtocolError – If, building from fields, version names neither member, or is not this class’s own version: that of the member it is or derives from, which a subclass outside the members does not have.

static __new__(cls, file=None, length=None, **kwargs)[source]

Create the member a construction of this class describes.

The version keyword names the member, on either path, and nothing else does: an ICMP message carries no version of its own, and no field picks a member. That member’s __init__ then runs with the same arguments. A subclass of this class is created as itself.

Parameters:
  • file (IO[bytes] | bytes | None) – Source packet stream.

  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

ICMP

Returns:

An uninitialised instance of the member.

Raises:

ProtocolError – If version is missing, or names neither member. Without it, octets are refused as fields are: the IP layer names the version, by protocol number 1 or 58.

static _member_of_version(version)[source]

The member a version of 4 or 6 names.

Parameters:

version (Any) – Version of ICMP.

Return type:

Type[ICMP]

Returns:

ICMPv4 or ICMPv6.

Raises:

ProtocolError – If version is neither, or is no int: a bool or a float is refused even where it equals one.

Footnotes