EtherLib/packet_registry.h
2022-10-27 21:03:58 +02:00

51 lines
1.7 KiB
C

#ifndef ETHERLIB_PACKET_REGISTRY_H
#define ETHERLIB_PACKET_REGISTRY_H
#include <stdint.h>
/**
* Boolean on 8-bits, not full machine-word size.
*/
typedef uint8_t bool8_t;
/**
* \typedef PcktProps
* \brief Packet properties
*
* Every packet property structure must extend this base structure,
* so that, must begin with fields defined here. PcktProps is guaranteed
* to be aligned to 32-bit boundary and so must be guaranteed by extending
* as well. (The size of the packet is divisible by 4.)
*/
typedef struct {
uint16_t headerSize; ///< Header size in bytes
uint16_t containedPacketID; ///< ID of contained packet. Zero if no packet contained.
bool8_t checksumOK; ///< Indicates that checksum is OK.
} PcktProps;
/**
* @typedef int (*PcktProcFn)(const uint8_t *pHdr, uint32_t size, uint8_t *pPcktProps);
* @brief Pckt processing function template.
* @param pHdr: pointer to the packet header
* @param size: remaining packet size counted from pHdr
* @param pPcktProps: pointer to existing structure to store
* packet properties to (e.g. source address, port etc.)
* @return packet type of contained packet, or -1 on failure or
* 0 if no more standard packet contained (e.g. UDP packet contains
* user data)
*/
typedef int (*PcktProcFn)(const uint8_t *pHdr, uint32_t size, uint8_t *pProps);
/**
* @struct PcktTypeDesc
* Pckt type descriptor. Pckt parsers can be registered
* using PcktTypeDesc assignments.
*
*/
typedef struct {
uint16_t type; ///< Type identification the packet (unique!)
uint16_t containerType; ///< Type of container packet packet (e.g.: IPv4 in case of UDP)
PcktProcFn procFun; ///< Pckt processing function
} PcktTypeDesc;
#endif //ETHERLIB_PACKET_REGISTRY_H