45 lines
1.2 KiB
C
45 lines
1.2 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)
|
|
|
|
typedef uint8_t EthernetAddress[ETH_HW_ADDR_LEN];
|
|
|
|
/**
|
|
* @struct EthernetProps
|
|
* Ethernet frame properties
|
|
*/
|
|
typedef struct {
|
|
PcktPropsHeader;
|
|
EthernetAddress destAddr[ETH_HW_ADDR_LEN]; ///< destination address
|
|
EthernetAddress sourceAddr[ETH_HW_ADDR_LEN]; ///< source address
|
|
uint16_t length_type; ///< frame length_type
|
|
} EthernetProps;
|
|
|
|
/**
|
|
* Parse raw Ethernet frames.
|
|
* @param hdr pointer to the Ethernet packet header
|
|
* @param size total frame size
|
|
* @param props 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, PcktProps * props);
|
|
|
|
/**
|
|
* 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
|