Base Protocol¶
pcapkit.protocols.internet.internet contains Internet,
which is a base class for internet layer protocols, eg. AH,
IPsec, IPv4,
IPv6, IPX, and etc.
- class pcapkit.protocols.internet.internet.Internet(file=None, length=None, **kwargs)[source]¶
Bases:
ProtocolBase[_PT,_ST],Generic[_PT,_ST]Abstract base class for internet layer protocol family.
This class parses the following protocols, which are registered in the
self.__proto__attribute:Index
Protocol
- classmethod register(code, protocol)[source]¶
Register a new protocol class.
Notes
The fully qualified class name should be
{protocol.module}.{protocol.name}.- Parameters:
protocol (
ModuleDescriptor[ProtocolBase] |Type[ProtocolBase]) – module descriptor or aProtocolsubclass
- Raises:
pcapkit.utilities.exceptions.RegistryError – If
protocolis not a class, or not aProtocolsubclass.- Warns:
pcapkit.utilities.warnings.RegistryWarning – If this protocol number 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; see
ProtocolBase.registerfor the guard this shares withregister_protocol.
- _decode_next_layer(dict_, proto=None, length=None, *, packet=None, version=4, ipv6_exthdr=None, payload=None)[source]¶
Decode next layer extractor.
- Parameters:
dict_ (
TypeVar(_PT, bound= Data)) – info bufferpacket (
dict[str,Any] |None) – packet info (passed fromself.unpack)version (
Literal[4,6]) – IP versionipv6_exthdr (
ProtoChain|None) – protocol chain of IPv6 extension headerspayload (
bytes|None) – payload from packet. If not provided, will extract fromself.__header__.get_payload
- Return type:
TypeVar(_PT, bound= Data)- Returns:
Current protocol with next layer extracted.
Notes
dict_gains the key__next_type__(next layer protocol type) and__next_name__(next layer protocol name). Neither is included whenInfo.to_dictis called.
- _import_next_layer(proto, length=None, *, packet=None, version=4, extension=False, payload=None)[source]¶
Import next layer extractor.
- Parameters:
proto (
int) – next layer protocol indexpacket (
dict[str,Any] |None) – packet info (passed fromself.unpack)version (
Literal[4,6]) – IP protocol versionextension (
bool) – if is extension headerpayload (
bytes|None) – payload from packet. If not provided, will extract fromself.__header__.get_payload
- Return type:
- Returns:
Instance of next layer.
- __proto__: DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, c.f.
self._decode_next_layer&self._import_next_layer.- Type:
DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]