26 lines
949 B
C
26 lines
949 B
C
//
|
|
// Created by epagris on 2022.11.03..
|
|
//
|
|
|
|
#include <memory.h>
|
|
#include <stdbool.h>
|
|
#include "ethernet_frame.h"
|
|
#include "etherlib/utils.h"
|
|
|
|
#define ETH_ETHERTYPE_LENGTH_THRESHOLD (1500)
|
|
#define ETH_ETHERNET_HEADER_SIZE (14)
|
|
|
|
int parse_ethernet(const uint8_t *hdr, uint32_t size, PcktProps * props) {
|
|
EthernetProps * frameProps = (EthernetProps *)props;
|
|
COPY_ADVANCE(frameProps->destAddr, hdr, ETH_HW_ADDR_LEN); // copy destination address
|
|
COPY_ADVANCE(frameProps->sourceAddr, hdr, ETH_HW_ADDR_LEN); // copy destination address
|
|
COPY_WORD_H2N_ADVANCE(&frameProps->length_type, hdr); // copy length/type field
|
|
|
|
// fill-in packet property header fields
|
|
frameProps->validityOK = true;
|
|
frameProps->containedPacketClass =
|
|
frameProps->length_type <= ETH_ETHERTYPE_LENGTH_THRESHOLD ? 0 : frameProps->length_type;
|
|
frameProps->headerSize = ETH_ETHERNET_HEADER_SIZE;
|
|
|
|
return frameProps->containedPacketClass;
|
|
} |