Ethernet Protocol¶
Removed in version 1.6.0: pcapkit.protocols.link.ethernet.PAT_MAC_ADDR, with no alias:
_read_mac_addr() and
_make_mac_addr() read and make the address
(#2614).
pcapkit.protocols.link.ethernet.protocol contains
Ethernet
only, which implements the extractor for Ethernet
Protocol [*], whose structure is:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Destination MAC Address |
6 |
48 |
|
Source MAC Address |
12 |
96 |
|
Length/Type |
The Length/Type field is an EtherType from 0x0600 up. Up to 0x05DC it is
the length of an IEEE 802.2 LLC
PDU, and the octets past it are kept as ethernet.trailer
(IEEE Std 802.3-2022 §3.2.6).
- class pcapkit.protocols.link.ethernet.protocol.Ethernet(file, length=None, /, *, layer=None, protocol=None, context=None)[source]¶
Bases:
Link[Ethernet,Ethernet]This class implements Ethernet Protocol.
The Length/Type field is an EtherType from
0x0600up, and the payload is dispatched throughLink.__proto__. Up to0x05DCit is the length of the MAC client data, an IEEE 802.2LLCPDU, and the octets past it, the pad among them, are kept astrailer(IEEE Std 802.3-2022 §3.2.6). A value between the two is neither, and its payload is kept asRaw.Changed in version 1.9.0: A Length/Type field up to
0x05DCis a length, and the payload it bounds is dissected as LLC, where it was kept raw;make()takes thetrailer(#2936).Changed in version 1.6.0:
typeofmake()takes a member or anintcode, resolved with the enumeration’sget; a name, abool, or a code the field cannot carry raisesProtocolError, rather than resolving against an enumeration inferred from the caller’s frame or writing a different value (#2594).Removed in version 1.6.0: The
type_default,type_namespaceandtype_reversedarguments ofmake(); resolve a name withresolve_index()first (#2594).Properties
Methods
- 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, payload=b'', trailer=b'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
type (
EtherType|int) – Length/Type: an EtherType, or, up to0x05DC, the length of the payload, which it has to be but in a rebuild of a cut frame.payload (
bytes|ProtocolBase|Schema) – Payload data.trailer (
bytes) – Octets after the payload a length gives, such as the pad; written as is.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
dstorsrcis rejected by_make_mac_addr(); iftypeis a name, abool, or a member or code its field cannot carry; if a length is not that ofpayload; or iftraileris given with no length to end the payload.
Data Models
Utilities
- _import_next_layer(proto, length=None, *, packet=None)[source]¶
Import next layer extractor.
- Parameters:
- Returns:
LLCwhereprotois a length, and otherwise the classLink.__proto__registers for it.- Return type:
Header Schemas¶
Removed in version 1.6.0: pcapkit.protocols.schema.link.ethernet, with no alias: the module moved here
(#2534).
- class pcapkit.protocols.link.ethernet.schema.Ethernet(dst=NO_VALUE, src=NO_VALUE, type=NO_VALUE, payload=NO_VALUE, trailer=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for ethernet packet.
Auxiliary Functions¶
- pcapkit.protocols.link.ethernet.schema.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:
LLCwheretypeis a length, and the class registered for it otherwise.- Return type:
None; the resolved class is assigned toself.protocol
Important
The lookup goes through
Protocol._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).
- pcapkit.protocols.link.ethernet.schema.ethernet_payload_length(pkt)[source]¶
Length of the
Ethernet.payloadfield.- Parameters:
- Return type:
- Returns:
The Length/Type field where it is a length (IEEE Std 802.3-2022 §3.2.6), so that the pad after the MAC client data is
Ethernet.trailer; the rest of the frame otherwise.
Data Models¶
Removed in version 1.6.0: pcapkit.protocols.data.link.ethernet, with no alias: the module moved here
(#2534).
Constants¶
Added in version 1.9.0.
- pcapkit.protocols.link.ethernet.const.LENGTH_MAX¶
Largest value of the Length/Type field that is a length, the number of octets of MAC client data, rather than an EtherType (IEEE Std 802.3-2022 §3.2.6). An EtherType is
0x0600or more, and the values between are neither.
Footnotes