BSD Loopback Encapsulation¶
Removed in version 1.6.0: pcapkit.protocols.link.loopback.family_byteorder, with no alias:
pcapkit.protocols.link.loopback exports the protocol class alone
(#2534).
Removed in version 1.7.0: pcapkit.protocols.link.loopback.protocol.family_byteorder, now
pcapkit.corekit.schema.byteorder.family_byteorder() (#2897).
pcapkit.protocols.link.loopback.protocol contains
Loopback,
which implements the extractor for the BSD loopback
encapsulation [*] of LINKTYPE_NULL and LINKTYPE_LOOP,
whose structure is:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Address Family (Internet Layer) |
The address family is in the byte order of the capturing host for
LINKTYPE_NULL, which no capture format records, so it is inferred from the
octets; for LINKTYPE_LOOP it is always in network byte order. Either way it
is kept as loopback.byteorder.
- class pcapkit.protocols.link.loopback.protocol.Loopback(file, length=None, /, *, byteorder=None, layer=None, protocol=None, context=None)[source]¶
Bases:
Link[Loopback,Loopback]This class implements BSD Loopback Encapsulation.
- Overloads:
file (
IO[bytes] |bytes), length (int|None) =..., /, *, byteorder (Literal['big','little'] |None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...*, byteorder (
Literal['big','little'] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =..., **fields (Any)
The header is one 4-octet address family, in the byte order of the host that captured the packet for
LINKTYPE_NULLand in network byte order forLINKTYPE_LOOP. Which link type a frame was captured under is thealiasit was dispatched with; forLINKTYPE_NULL, which a frame parsed on its own is read as, the byte order is read from the octets themselves (seefamily_byteorder()). Either way it is kept ininfo, andfrom_datareads the family back in that byte order rather than inferring it again.The address families are those of the BSD socket API, whose
AF_INET6differs between the BSDs, so each of its values is read as IPv6. This class supports parsing of the following protocols, which are registered in theself.__proto__attribute:Index
Protocol
2
24
28
30
Any other family is kept as
Raw.Defaults
- __proto__: DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, see
self._decode_next_layer&self._import_next_layer. Keyed by address family rather than by EtherType, so this class keeps a registry of its own instead of sharingLink.__proto__; an entry is registered withregister_loopback().
Properties
Methods
- read(length=None, *, alias=None, byteorder=None, **kwargs)[source]¶
Read BSD Loopback Encapsulation.
Structure of the BSD loopback header:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Address Family | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Parameters:
alias (
int|None) – Link type the frame was dispatched under, asFrameandPCAPNGpass it;LINKTYPE_LOOPreads the family in network byte order, and anything else asLINKTYPE_NULL.byteorder (
Literal['big','little'] |None) – Byte order to read the family in, ahead ofalias.make()is handed the oneinfoholds byfrom_data, and it reaches here too, so a rebuild reads the family as it was parsed rather than inferring it again.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If
byteorderis neither'big'nor'little'.
- make(*, family=2, byteorder=sys.byteorder, payload=b'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
family (
int) – Address family, e.g. 2 for IPv4.byteorder (
Literal['big','little']) – Byte order to write the address family in, by default this host’s, as a capture of its own loopback interface does.payload (
bytes|ProtocolBase|Schema) – Payload data.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
byteorderis neither'big'nor'little', orfamilyis not anint(aboolincluded, #2289) or does not fit in 4 octets.
- classmethod register(code, protocol)[source]¶
Register a new protocol class for an address family.
Notes
The fully qualified class name of the new protocol class should be
{protocol.module}.{protocol.name}.- Parameters:
code (
int) – BSD address familyprotocol (
ModuleDescriptor[ProtocolBase] |Type[ProtocolBase]) – module descriptor or aProtocolBasesubclass
Important
This overrides
Link.registerbecauseself.__proto__is keyed by address family rather than by EtherType (#2511).- Raises:
pcapkit.utilities.exceptions.RegistryError – If
protocolis not a class, or not aProtocolBasesubclass.- Warns:
pcapkit.utilities.warnings.RegistryWarning– If this address family is already registered and the incumbent differs from the replacement; the message names both. SeeProtocol.registerfor the guard, and for the shipped descriptor a restore puts back (#1504).
Data Models
- __init__(file=NO_VALUE, length=None, /, *, byteorder=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) =..., /, *, byteorder (Literal['big','little'] |None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...→None*, byteorder (
Literal['big','little'] |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.byteorder (
Literal['big','little'] |None) – Byte order to read the family in, asread()takes it;Noneguesses it.layer (
str|None) – AsProtocol.__init__.protocol (
str|ProtocolBase|Type[ProtocolBase] |None) – AsProtocol.__init__.context (
ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) – AsProtocol.__init__.**fields (
Any) – AsProtocol.__init__.
Changed in version 1.8.0: Declares
byteorder, its only parse keyword besides the stops and the context (#2840).
Utilities
Header Schemas¶
Removed in version 1.6.0: pcapkit.protocols.schema.link.loopback, with no alias: the module moved here
(#2534).
- class pcapkit.protocols.link.loopback.schema.Loopback(family=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for BSD loopback encapsulation.
The address family is kept as its 4 octets, since their byte order depends on the link type the frame was captured under; see
family_byteorder().
Data Models¶
Removed in version 1.6.0: pcapkit.protocols.data.link.loopback, with no alias: the module moved here
(#2534).
- class pcapkit.protocols.link.loopback.data.Loopback(family, byteorder)[source]¶
Bases:
ProtocolData model for BSD loopback encapsulation.
Footnotes