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

ethernet.dst

Destination MAC Address

6

48

ethernet.src

Source MAC Address

12

96

ethernet.type

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: type of make() takes a member or an int code, resolved with the enumeration’s get; a name, a bool, or a code the field cannot carry raises ProtocolError, 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_namespace and type_reversed arguments of make(); resolve a name with resolve_index() first (#2594).

property name: Literal['Ethernet Protocol']

Name of current protocol.

property length: Literal[14]

Header length of current protocol.

property protocol: EtherType

Name of next layer protocol.

property src: str

Source mac address.

property dst: str

Destination mac address.

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           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

Ethernet

Returns:

Parsed packet data.

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:

Ethernet

Returns:

Constructed packet data.

Raises:

ProtocolError – If dst or src is rejected by _make_mac_addr(), or type is a name, a bool, or a member or code its field cannot carry.

classmethod __index__()[source]

Numeral registry index of the protocol.

Return type:

LinkType

Returns:

Numeral registry index of the protocol in tcpdump link-layer header types.

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (Ethernet) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

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: Schema

Header schema for ethernet packet.

dst: bytes = <BytesField dst>

Destination MAC address.

src: bytes = <BytesField src>

Source MAC address.

type: EtherType = <EnumField type>

Protocol (internet layer).

payload: bytes = <PayloadField payload>

Payload.

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, whose type names the next layer.

Returns:

None; the resolved class is assigned to self.protocol.

Important

The lookup goes through Protocol._lookup_next_layer rather than subscripting the registry. Ethernet.__proto__ is Link.__proto__, a class-level collections.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, and Link.register would afterwards report it as an overwrite. The helper reads the fallback without recording it, and resolves a ModuleDescriptor without 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: Protocol

Data model for ethernet packet.

dst: str

Destination MAC address.

src: str

Source MAC address.

type: EtherType

Protocol (internet layer).

Footnotes