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 currently supports parsing of the following protocols, which are registered in the
self.__proto__
attribute:Index
Protocol
- property layer: Literal['Internet']¶
Protocol layer.
- classmethod register(code, protocol)[source]¶
Register a new protocol class.
Notes
The full qualified class name of the new protocol class should be as
{protocol.module}.{protocol.name}
.- Parameters:
protocol (
Union
[ModuleDescriptor
[ProtocolBase
],Type
[ProtocolBase
]]) – module descriptor or aProtocol
subclass
- Return type:
- _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 (
Optional
[dict
[str
,Any
]]) – packet info (passed fromself.unpack
)version (
Literal
[4
,6
]) – IP versionipv6_exthdr (
Optional
[ProtoChain
]) – protocol chain of IPv6 extension headerspayload (
Optional
[bytes
]) – 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
We added a new key
__next_type__
todict_
to store the next layer protocol type, and a new key__next_name__
to store the next layer protocol name. These two keys will NOT be included whenInfo.to_dict
is 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 (
Optional
[dict
[str
,Any
]]) – packet info (passed fromself.unpack
)version (
Literal
[4
,6
]) – IP protocol versionextension (
bool
) – if is extension headerpayload (
Optional
[bytes
]) – payload from packet. If not provided, will extract fromself.__header__.get_payload
- Return type:
- Returns:
Instance of next layer.
- __layer__: Optional[Literal["Link", "Internet", "Transport", "Application"]]¶
Layer of protocol.
- __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[Protocol] | Type[Protocol]]