summaryrefslogtreecommitdiff
path: root/common/include/decode_ipv4.h
blob: 73cacd1f4a60fb9d3362130def1a6f2c85689040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#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