#ifndef ETHERLIB_IPV4_PACKET_H #define ETHERLIB_IPV4_PACKET_H #include #include "../../packet_registry.h" #include "../../packet_sieve.h" #include "ipv4_types.h" #define ETH_IPv4_PACKET_CLASS (0x0800) #define ETH_IPv4_HEADER_SIZE (20) /** * IPv4 header structure */ typedef struct { PcktPropsHeader // 1. 32-bit uint8_t IHL; ///< header size uint8_t Version; ///< version (always 4) uint8_t DSF; ///< service type uint16_t TotalLength; ///< total packet length // 2. 32-bit uint16_t Identification; ///< identification uint8_t Flags; ///< packet flags uint16_t FragmentOffset; ///< packet fragmentation offset // 3. 32-bit uint8_t TTL; ///< Time-To-Live uint8_t Protocol; ///< Protocol uint16_t HeaderChecksum; ///< header IP-checksum // 4. 32-bit uint32_t SourceIPAddr; ///< source IP-address uint32_t DestIPAddr; ///< destination IP-address } IPv4Props; struct EthInterface_; /** * Parse raw IPv4 packets. * @param hdr pointer to the IPv4 packet header * @param size total packet size * @param pcktHdrLe pointer to property storage * @return Protocol on success or -1 on failure */ int parse_ipv4(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf); /** * Insert IPv4 header. * @param hdr space where the header is to be inserted * @param headers linked list of header, top is always relevant */ void insert_ipv4_header(uint8_t * hdr, const PcktHeaderElement * headers); /** * Calculate Ethernet IPv4 multicast address from multicast * @param hwa * @param ipa */ void ethmc_from_ipmc(uint8_t * hwa, ip4_addr ipa); #endif //ETHERLIB_IPV4_PACKET_H