summaryrefslogtreecommitdiff
path: root/common/include/decode_ipv6.h
blob: 9bb0d36ef99df116e44fd63b7728ed9542d738a0 (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
56
57
58
#ifndef _DECODE_IPV6_H
#define _DECODE_IPV6_H

#ifdef __cpluscplus
extern "C"
{
#endif

#include "public.h"

#define IPV6_HEADER_LEN 40

    typedef struct ipv6_header_s
    {
        union
        {
            struct ip6_un1_
            {
                uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
                uint16_t ip6_un1_plen; /* payload length */
                uint8_t ip6_un1_nxt;   /* next header */
                uint8_t ip6_un1_hlim;  /* hop limit */
            } ip6_un1;
            uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
        } ip6_hdrun;

        union
        {
            struct
            {
                uint32_t ip6_src[4];
                uint32_t ip6_dst[4];
            } ip6_un2;
            uint16_t ip6_addrs[16];
        } ip6_hdrun2;
    } __attribute__((__packed__)) ipv6_header_t;

    typedef struct ipv6_info_s
    {
        char src_addr[INET6_ADDRSTRLEN];
        char dst_addr[INET6_ADDRSTRLEN];

        ipv6_header_t *hdr;
        uint8_t *payload;
        uint8_t next_protocol;

        uint32_t hdr_len;
        uint32_t payload_len;
    } ipv6_info_t;

    int decode_ipv6(ipv6_info_t *packet, const uint8_t *data, uint32_t len);
    void dump_ipv6_info(uint32_t pkt_id, ipv6_info_t *packet);

#ifdef __cpluscplus
}
#endif

#endif