55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
#ifndef _DECODE_IPV4_H
|
|
#define _DECODE_IPV4_H
|
|
|
|
#ifdef __cpluscplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include "public.h"
|
|
|
|
#define IPV4_HEADER_LEN 20
|
|
|
|
typedef struct ipv4_header_s
|
|
{
|
|
uint8_t ip_verhl; // version & header length
|
|
uint8_t ip_tos;
|
|
uint16_t ip_len;
|
|
uint16_t ip_id;
|
|
uint16_t ip_off;
|
|
uint8_t ip_ttl;
|
|
uint8_t ip_proto;
|
|
uint16_t ip_csum;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
struct in_addr ip_src;
|
|
struct in_addr ip_dst;
|
|
} ip4_un1;
|
|
uint16_t ip_addrs[4];
|
|
} ip4_hdrun1;
|
|
} __attribute__((__packed__)) ipv4_header_t;
|
|
|
|
typedef struct ipv4_info_s
|
|
{
|
|
char src_addr[INET_ADDRSTRLEN];
|
|
char dst_addr[INET_ADDRSTRLEN];
|
|
|
|
ipv4_header_t *hdr;
|
|
uint8_t *payload;
|
|
uint8_t next_protocol;
|
|
|
|
uint32_t hdr_len;
|
|
uint32_t opts_len;
|
|
uint32_t payload_len;
|
|
} ipv4_info_t;
|
|
|
|
int decode_ipv4(ipv4_info_t *packet, const uint8_t *data, uint32_t len);
|
|
int dump_ipv4_info(ipv4_info_t *packet, char *buff, size_t size);
|
|
|
|
#ifdef __cpluscplus
|
|
}
|
|
#endif
|
|
|
|
#endif |