BSD Loopback Encapsulation¶
Removed in version 1.6.0: pcapkit.protocols.link.loopback.family_byteorder, with no alias: it is in this
module, and pcapkit.protocols.link.loopback exports the protocol class alone
(#2534).
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=None, length=None, **kwargs)[source]¶
Bases:
Link[Loopback,Loopback]This class implements BSD Loopback Encapsulation.
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.- __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().
- 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).
- pcapkit.protocols.link.loopback.protocol.family_byteorder(family, linktype=None)[source]¶
Byte order a loopback header’s address family was written in.
- Parameters:
- Return type:
Literal['big','little']- Returns:
'big'forLINKTYPE_LOOP(108), whose family is in network byte order. Otherwise, forLINKTYPE_NULL(0),'big'if the octets read as a smaller number big-endian than little-endian, else'little'.
Note
A
LINKTYPE_NULLfamily is in the byte order of the host that captured the packet, which the capture file does not record. Every address family is below0x10000, so its zero octets lie at the high end, and the smaller of the two readings is the one in the writer’s byte order. A family that reads the same both ways, such as 0, packs to the same octets either way. ALINKTYPE_LOOPfamily is never inferred, so one written little-endian reads as a family no table holds.
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