Ethernet Protocol¶
pcapkit.protocols.link.ethernet contains
Ethernet
only, which implements extractor for Ethernet
Protocol [*], whose structure is described as
below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Destination MAC Address |
6 |
48 |
|
Source MAC Address |
12 |
96 |
|
Protocol (Internet Layer) |
- class pcapkit.protocols.link.ethernet.Ethernet(file=None, length=None, **kwargs)[source]¶
Bases:
Link[Ethernet,Ethernet]This class implements Ethernet Protocol.
- read(length=None, **kwargs)[source]¶
Read Ethernet Protocol.
Structure of Ethernet header [RFC 7042]:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Dst MAC Addr | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Src MAC Addr | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Ether Type | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- make(dst='00:00:00:00:00:00', src='00:00:00:00:00:00', type=<EtherType.Internet_Protocol_version_4: 2048>, type_default=None, type_namespace=None, type_reversed=False, payload=b'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
type (
EtherType|IntEnum|IntEnum|str|int) – EtherType.type_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – EtherType namespace.type_reversed (
bool) – Whether EtherType is reversed.payload (
bytes|ProtocolBase|Schema) – Payload data.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
Header Schemas¶
- class pcapkit.protocols.schema.link.ethernet.Ethernet(*args: _VT, **kwargs: _VT)[source]¶
Bases:
SchemaHeader schema for ethernet packet.
Auxiliary Functions¶
- pcapkit.protocols.schema.link.ethernet.callback_payload(self, packet)[source]¶
Callback function for
Ethernet.payload.- Parameters:
self (
PayloadField) – Payload field to resolve.packet (
dict[str,Any]) – Packet data, whosetypenames the next layer.
- Returns:
None; the resolved class is assigned toself.protocol.
Important
The lookup goes through
ProtocolBase._lookup_next_layerrather than subscripting the registry.Ethernet.__proto__isLink.__proto__, a class-levelcollections.defaultdict, so subscripting it with a missing key would insert that key – every unregistered EtherType a parse saw would be recorded as though somebody had registered it, andLink.registerwould afterwards report it as an overwrite. The helper reads the fallback without recording it, and resolves aModuleDescriptorwithout writing the class back, so the registry is left as registered (#1559).
Data Models¶
- class pcapkit.protocols.data.link.ethernet.Ethernet(*args: VT, **kwargs: VT)[source]¶
Bases:
ProtocolData model for ethernet packet.
Footnotes