EtherLib/prefab/packet_parsers/ethernet_frame.h
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

55 lines
1.5 KiB
C

//
// Created by epagris on 2022.11.03..
//
#ifndef ETHERLIB_ETHERNET_FRAME_H
#define ETHERLIB_ETHERNET_FRAME_H
#include <stdint.h>
#include "../../packet_registry.h"
#include "../../packet_sieve.h"
#define ETH_HW_ADDR_LEN (6)
#define ETH_ETHERNET_HEADER_SIZE (14)
#define HEADER_FETCH_PROPS(T,h) (T *)(&((h)->props))
#define ALLOC_HEADER_ELEMENT(T) (PcktHeaderElement *) dynmem_alloc(ETH_PCKT_HEADER_ELEMENT_HEAD_SIZE + sizeof(T))
#define HWACPY(dst,src) memcpy((dst),(src), ETH_HW_ADDR_LEN)
typedef uint8_t EthernetAddress[ETH_HW_ADDR_LEN];
extern EthernetAddress ETH_ETHERNET_IPMC_HWADDR;
/**
* @struct EthernetProps
* Ethernet frame properties
*/
typedef struct {
PcktPropsHeader;
EthernetAddress destAddr; ///< destination address
EthernetAddress sourceAddr; ///< source address
uint16_t length_type; ///< frame length_type
} EthernetProps;
struct EthInterface_;
/**
* Parse raw Ethernet frames.
* @param hdr pointer to the Ethernet packet header
* @param size total frame size
* @param pcktHdrLe pointer to property storage
* @return EtherType or 0 (if size is less than 1500) on success or -1 on error
*/
int parse_ethernet(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf);
/**
* Insert Ethernet header to specified address.
* @param hdr space where the header is to be inserted
* @param headers linked list of header, top is always relevant
*/
void insert_ethernet_header(uint8_t * hdr, const PcktHeaderElement * headers);
#endif //ETHERLIB_ETHERNET_FRAME_H