Sub topic 6
How a MAC Address Is Used in an Ethernet Frame
This chapter assumes you can read hexadecimal, know that a MAC address is 48 bits long, and know the difference between unicast, multicast, and broadcast destinations. It covers where the two MAC addresses sit in an Ethernet II frame and how each receiver uses them.
The Ethernet II frame layout
A frame is the unit of data that the link layer sends across one local network. In Ethernet II, the header holds three fields and is 14 bytes long. The payload follows the header, and a trailer follows the payload.
| Field | Size | Purpose |
|---|---|---|
| Destination MAC | 6 bytes | Who should receive this frame |
| Source MAC | 6 bytes | Which interface sent it |
| EtherType | 2 bytes | Which protocol the payload carries |
| Payload | 46 to 1500 bytes | The packet, such as IPv4, IPv6, or ARP |
| FCS | 4 bytes | Frame check sequence, a CRC to detect corruption |
The destination comes first. A network card can therefore read the first 6 bytes and decide quickly whether the frame is meant for it.
The EtherType tells the receiver which protocol should get the payload. Common values are 0x0800 for IPv4, 0x86dd for IPv6, and 0x0806 for ARP.
Before the header, the sender transmits a preamble that lets the receiver synchronize. The network hardware adds and removes the preamble. Capture tools such as Wireshark normally do not show it. The FCS is usually stripped before a capture tool sees the frame.
What the receiver does with the destination MAC
Every network interface compares the destination MAC of each arriving frame with a short list of addresses it accepts. Normally, the frame is accepted when the destination is:
- The interface's own unicast MAC address.
- The broadcast address
ff:ff:ff:ff:ff:ff. - A multicast address the host has subscribed to.
The interface drops all other frames in hardware, and the operating system never sees them. Promiscuous mode turns this filter off so the interface passes every frame it receives upward. Packet capture tools use this mode. On a switched network, promiscuous mode still shows only the frames the switch sends to your port.
The source MAC is never a group address. A sender always writes its own unicast address there. Receivers and switches use the source address to learn who is on the network, which later chapters cover.
Parsing a header in Python
You can unpack the first 14 bytes with the struct module. The format !6s6sH means network byte order, two 6-byte strings, and one unsigned 16-bit integer.
import struct
def parse_ethernet_header(frame: bytes) -> dict:
if len(frame) < 14:
raise ValueError('an Ethernet II header is 14 bytes')
dst, src, ethertype = struct.unpack('!6s6sH', frame[:14])
fmt = lambda b: ':'.join(f'{x:02x}' for x in b)
return {'dst': fmt(dst), 'src': fmt(src), 'ethertype': hex(ethertype)}
# ARP request header: broadcast destination, EtherType 0x0806
header = bytes.fromhex('ffffffffffff' '020000000001' '0806')
print(parse_ethernet_header(header))The output is:
{'dst': 'ff:ff:ff:ff:ff:ff', 'src': '02:00:00:00:00:01', 'ethertype': '0x806'}Python's hex() drops the leading zero, so 0x0806 prints as 0x806. The destination is the broadcast address, so every host on the LAN accepts this frame. The source starts with 02, so its locally administered bit is set.
Common mistakes
- Reading the fields in the wrong order. The destination is first and the source is second. Swapping them is a frequent error when reading a hex dump.
- Treating the 2-byte field as always a type. Values of
0x0600(1536) and above are EtherTypes. Smaller values are lengths in the older IEEE 802.3 format. Modern traffic uses EtherType values. - Expecting the MAC addresses to describe the end hosts. The frame addresses only travel across one link. After a router, the next frame has new MAC addresses, which a later chapter covers.
- Forgetting the minimum size. The payload is padded to 46 bytes if it is shorter, so a minimum frame is 64 bytes with the FCS.
Checking a frame yourself
Capture a few frames and read the first 14 bytes. On Linux, tcpdump -e -n -c 5 prints the link-layer header for each frame, including both MAC addresses and the EtherType. Compare the output with the table above.
Exercise
A frame begins with the bytes 00 1a 2b 3c 4d 5e 02 00 00 00 00 01 08 00. What are the destination MAC, the source MAC, and the payload protocol? Would a host whose MAC is 02:00:00:00:00:01 accept this frame?
Show answer
The destination is 00:1a:2b:3c:4d:5e, the source is 02:00:00:00:00:01, and the EtherType 0x0800 means the payload is IPv4. The host with MAC 02:00:00:00:00:01 would not accept it. That address is the source, not the destination, and the destination is neither broadcast nor a multicast address.
Exercise
Why does the Ethernet header put the destination MAC before the source MAC?
Show answer
The receiving interface can compare the first 6 bytes with the addresses it accepts and drop a frame that is not for it, without reading the rest of the header.