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 |
|
Protocol (Internet Layer) |
- class pcapkit.protocols.link.ethernet.protocol.Ethernet(file=None, length=None, **kwargs)[source]¶
Bases:
Link[Ethernet,Ethernet]This class implements Ethernet Protocol.
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).- 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'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
dstorsrcis rejected by_make_mac_addr(), ortypeis a name, abool, or a member or code its field cannot carry.
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, *, __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:
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).
Data Models¶
Removed in version 1.6.0: pcapkit.protocols.data.link.ethernet, with no alias: the module moved here
(#2534).
- class pcapkit.protocols.link.ethernet.data.Ethernet(dst, src, type)[source]¶
Bases:
ProtocolData model for ethernet packet.
Footnotes