BSD Loopback Encapsulation¶
pcapkit.protocols.link.loopback contains
Loopback
only, which implements extractor for the BSD loopback
encapsulation [*] of LINKTYPE_NULL and LINKTYPE_LOOP,
whose structure is described as below:
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.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.- 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='little', 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', orfamilydoes not fit in 4 octets.
- __proto__: DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, c.f.
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__.- Type:
DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]
- pcapkit.protocols.link.loopback.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¶
Data Models¶
- class pcapkit.protocols.data.link.loopback.Loopback(*args: VT, **kwargs: VT)[source]¶
Bases:
ProtocolData model for BSD loopback encapsulation.
Footnotes