IP - Internet Protocol¶
pcapkit.protocols.internet.ip.protocol contains
IP only,
which is a base class for Internet Protocol (IP)
protocol family [*], e.g.
IPv4 and
IPv6. Parsing octets through the base,
or building it from fields, gives the one its version keyword names,
which a member checks as its own on both paths (#2840); without it, octets
give the one their Version field names, and fields are refused. Its
from_data() reads the version of its
data (#2574).
- class pcapkit.protocols.internet.ip.protocol.IP[_PT: Data, _ST: Schema](file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[source]¶
Bases:
Internet[_PT,_ST],Generic[_PT,_ST]Base class for the IP protocol family.
The IPsec protocols (
AHandESP) derive fromIPsecinstead.It dispatches on both paths, never giving an instance of this class (#2574).
versionnames the member; without it, octets give the one their Version field names, and fields are refused, since no field picks a member.from_data()reads theversionof its data. See__new__().Methods
- classmethod from_data(data, /, **kwargs)[source]¶
Create protocol instance from data.
- Parameters:
**kwargs (
Any) – AsProtocol.from_data.
- Return type:
- Returns:
Protocol instance; on this class, an instance of the member the
versionofdatanames, which both data models carry.- Raises:
ProtocolError – If that
versionis neither4nor6, on this class.
Data Models
- __init__(file=NO_VALUE, length=None, /, *, version=None, layer=None, protocol=None, context=None, **fields)[source]¶
Parse a protocol instance from its octets, or construct one from its fields.
- Overloads:
file (
IO[bytes] |bytes), length (int|None) =..., /, *, version (Literal[4,6] |None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...→None*, version (
Literal[4,6] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =..., **fields (Any) →None
- Parameters:
file (
IO[bytes] |bytes|NoValueType) – Source packet stream; omitted to construct.version (
Literal[4,6] |None) – Version of IP,4or6: the member__new__()picks, which must be this class’s own.layer (
str|None) – AsProtocol.__init__.protocol (
str|ProtocolBase|Type[ProtocolBase] |None) – AsProtocol.__init__: onIPv4, a field given nofile.context (
ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) – AsProtocol.__init__.**fields (
Any) – AsProtocol.__init__.
- Raises:
ProtocolError – If
versionnames 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.
Changed in version 1.8.0:
versionis checked against the member, asfrom_fields()checks it (#2840).
- static __new__(cls, file=NO_VALUE, length=None, /, **kwargs)[source]¶
Create the member a parse or a construction of this class describes.
The
versionkeyword names the member. Without it, the octets give the member the Version field in their first four bits names, and fields are refused. That member’s__init__then runs with the same arguments. A subclass of this class is created as itself.- Parameters:
- Return type:
- Returns:
An uninitialised instance of the member.
- Raises:
ProtocolError – On this class, if
versionnames neither member; if, without it, the octets are empty or their first four bits name neither version; or if fields come without it.
Utilities
- classmethod _construction_member(fields)[source]¶
The member
from_fields(),from_data()and a call given no file construct.On this class, the member
versionnames; on another, the class itself, of whichversionmust name the member it is or derives from.versionis taken out offields, asmake()does not read it.- Parameters:
- Return type:
- Returns:
The member, or the class itself.
- Raises:
ProtocolError – If, on this class,
versionis missing; if it names neither member; or if it is not the class’s own version, which a subclass outside the members does not have.
Added in version 1.8.0.
Footnotes