Search code examples
pythonnetwork-programmingipethernetpacket

Doesn't the ethernet data always contain the IP packet?


I have a question about the following code written in Python:

def parse_ethernet(timestamp, packet)
    ethernet = dpkt.ethernet.Ethernet(packet)
    if isinstance(ethernet.data,dpkt.ip.IP):
        parse_ip(ethernet.data)

The idea of the code is to parse the ethernet packet using dpkt library in python. My question is regarding the following line:

if isinstance(ethernet.data,dpkt.ip.IP):

Why do we need to prove if the ethernet.data is an instance of the IP packet? Doesn't the ethernet data always contain the IP packet?


Solution

  • Why do we need to prove if the ethernet.data is an instance of the IP packet? Doesn't the ethernet data always contain the IP packet?

    No, it doesn't. For example, for an ARP Request, the Ethernet frame contains an ARP packet, not an IP packet.

    In ATA-over-Ethernet, as the name says, the Ethernet frame contains an encapsulated ATA packet, not IP.

    Then there is AES51, AVB, SoundGrid, EtherSound, CobraNet, LLDP, FCoE, PTP (Layer 2), MACsec, EtherCAT, HyperSCSI, PROFINET, PPPoE, MPLS, IPX, AppleTalk, DECnet, and many, many, many others. Wikipedia lists over 50 protocols that are not IP for which an EtherType allocation exists.