EtherLib/prefab/packet_parsers/ethernet_frame.c
Wiesner András 05288d7a3c - ARP cache auto lookup feature added
- IGMPv2 capabilities added (report membership, leave group)
- ICMP capabilities added (ping)
- Tx Message Queue added
2023-01-14 14:24:56 +01:00

36 lines
1.4 KiB
C

//
// Created by epagris on 2022.11.03..
//
#include <memory.h>
#include <stdbool.h>
#include "ethernet_frame.h"
#include "../../utils.h"
#define ETH_ETHERTYPE_LENGTH_THRESHOLD (1500)
#define ETH_ETHERNET_HEADER_SIZE (14)
EthernetAddress ETH_ETHERNET_IPMC_HWADDR = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x00 };
int parse_ethernet(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf) {
EthernetProps * frameProps = (EthernetProps *) &pcktHdrLe->props;
FETCH_ADVANCE(frameProps->destAddr, hdr, ETH_HW_ADDR_LEN); // copy destination address
FETCH_ADVANCE(frameProps->sourceAddr, hdr, ETH_HW_ADDR_LEN); // copy destination address
FETCH_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;
}
void insert_ethernet_header(uint8_t *hdr, const PcktHeaderElement *headers) {
EthernetProps * ethProps = (EthernetProps *) &headers->props;
FILL_ADVANCE(hdr, ethProps->destAddr, ETH_HW_ADDR_LEN);
FILL_ADVANCE(hdr, ethProps->sourceAddr, ETH_HW_ADDR_LEN);
FILL_WORD_H2N_ADVANCE(hdr, ethProps->length_type);
}