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

eth.dst

Destination MAC Address

1

8

eth.src

Source MAC Address

2

16

eth.type

Protocol (Internet Layer)

class pcapkit.protocols.link.ethernet.Ethernet(file=None, length=None, **kwargs)[source]#

Bases: Link[Ethernet, Ethernet]

This class implements Ethernet Protocol.

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 (Optional[int]) – 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, type_default=None, type_namespace=None, type_reversed=False, payload=b'', **kwargs)[source]#

Make (construct) packet data.

Parameters:
Return type:

Ethernet

Returns:

Constructed packet data.

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.

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.

Header Schemas#

class pcapkit.protocols.schema.link.ethernet.Ethernet(dict_=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: Enum_EtherType = <EnumField type>#

Protocol (internet layer).

payload: bytes = <PayloadField payload>#

Payload.

Auxiliary Functions#

pcapkit.protocols.schema.link.ethernet.callback_payload(self, packet)[source]#

Callback function for Ethernet.payload.

Return type:

None

Data Models#

class pcapkit.protocols.data.link.ethernet.Ethernet(*args: VT, **kwargs: VT)[source]#

Bases: Protocol

Data model for ethernet packet.

dst: str#

Destination MAC address.

src: str#

Source MAC address.

type: EtherType#

Protocol (internet layer).

Footnotes