Link Layer Base Protocol¶
pcapkit.protocols.link.link contains Link,
which is a base class for link layer protocols, e.g.
ARP/InARP,
Ethernet, L2TP
and VLAN.
- class pcapkit.protocols.link.link.Link[_PT: Data, _ST: Schema](file=None, length=None, **kwargs)[source]¶
Bases:
ProtocolBase[_PT,_ST],Generic[_PT,_ST]Abstract base class for link layer protocol family.
This class supports parsing of the following protocols, which are registered in the
self.__proto__attribute:Index
Protocol
0x8137
- __proto__: DefaultDict[int | EtherType, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, see
self._decode_next_layer&self._import_next_layer.
- __proto_key__: ClassVar[tuple[Type[EnumRegistry], bool]]¶
What
__proto__is keyed by – the enum a key must be a member of, and whether a bareintis a valid key too. Declared by the class owning the registry and read byregister_protocol_code(), so acode=key is checked asregister_ethertype()checks its own. A class keeping its own registry, such asLoopback, declares its own pairing or none (#2268).
- classmethod register(code, protocol)[source]¶
Register a new protocol class.
Notes
The fully qualified class name of the new protocol class should be
{protocol.module}.{protocol.name}.- Parameters:
protocol (
ModuleDescriptor[ProtocolBase] |Type[ProtocolBase]) – module descriptor or aProtocolBasesubclass
- Raises:
pcapkit.utilities.exceptions.RegistryError – If
protocolis not a class, or not aProtocolBasesubclass.- Warns:
pcapkit.utilities.warnings.RegistryWarning– If this EtherType is already registered, naming the displaced entry and its replacement so a caller can tell what was lost. Fires only when the incumbent differs from the replacement – seeProtocol.registerfor the guard this shares withregister_protocol, and for the shipped descriptor that a restore puts back (#1504).
Changed in version 1.3.0: Takes the protocol as one
protocolargument, aModuleDescriptoror aProtocolBasesubclass, in place of themoduleandclass_names.
- __post_init__(file=None, length=None, **kwargs)[source]¶
Post initialisation hook.
- Parameters:
- Return type:
Notes
A header the data ends inside keeps that in its
info, so thatfrom_data()rebuilds only what was captured (#1458).