54 lines
1.4 KiB
C
54 lines
1.4 KiB
C
#ifndef ETHERLIB_IPV4_PACKET_H
|
|
#define ETHERLIB_IPV4_PACKET_H
|
|
|
|
#include <stdint.h>
|
|
#include "../../packet_registry.h"
|
|
#include "../../packet_sieve.h"
|
|
|
|
#define ETH_IPv4_PACKET_CLASS (0x0800)
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* Parse raw IPv4 packets.
|
|
* @param hdr pointer to the IPv4 packet header
|
|
* @param size total packet size
|
|
* @param props pointer to property storage
|
|
* @return Protocol on success or -1 on failure
|
|
*/
|
|
int parse_ipv4(const uint8_t *hdr, uint32_t size, PcktProps * props);
|
|
|
|
/**
|
|
* 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);
|
|
|
|
#endif //ETHERLIB_IPV4_PACKET_H
|