protos: added patchset for dissector by Markus Amend for ipv6, esp, ip auth
[netsniff-ng.git] / src / proto_ipv6_hop_by_hop.h
blob90f2108c7f391a6f70ba7555f37afdc00b4b1e1a
1 /*
2 * IPv6 Hop-By-Hop Header described in RFC2460
3 * programmed by Markus Amend 2012 as a contribution to
4 * netsniff-ng - the packet sniffing beast
5 * Copyright 2009, 2010 Daniel Borkmann.
6 * Copyright 2010 Emmanuel Roullit.
7 * Subject to the GPL, version 2.
8 */
10 #ifndef HOP_BY_HOP_H
11 #define HOP_BY_HOP_H
13 #include <stdio.h>
14 #include <stdint.h>
15 #include <netinet/in.h> /* for ntohs() */
17 #include "proto_struct.h"
18 #include "dissector_eth.h"
20 struct hop_by_hophdr {
21 uint8_t h_next_header;
22 uint8_t h_hdr_ext_len;
23 uint8_t h_hdr_option_type;
24 } __attribute__((packed));
26 static inline void hop_by_hop(uint8_t *packet, size_t len)
28 uint8_t hdr_ext_len;
30 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
32 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
34 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
35 return;
37 tprintf("\t [ Hop-By-Hop ");
38 tprintf("NextHdr (%u), ", hop_by_hop->h_next_header);
39 tprintf("HdrExtLen (%u), ", hdr_ext_len);
40 tprintf("Opt (%u), ", hop_by_hop->h_hdr_option_type);
41 tprintf("Appendix 0x");
42 for (uint8_t i=sizeof(struct hop_by_hophdr);i<hdr_ext_len;i++)
43 tprintf("%02x",(uint8_t) packet[i]);
44 tprintf(" ]\n");
47 static inline void hop_by_hop_less(uint8_t *packet, size_t len)
49 uint8_t hdr_ext_len;
51 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
53 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
55 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
56 return;
58 tprintf(" Hop-By-Hop Opt %u", hop_by_hop->h_hdr_option_type);
61 static inline void hop_by_hop_next(uint8_t *packet, size_t len,
62 struct hash_table **table,
63 unsigned int *key, size_t *off)
65 uint8_t hdr_ext_len;
67 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
69 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
71 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
72 goto invalid;
74 (*off) = hdr_ext_len;
75 (*key) = hop_by_hop->h_next_header;
76 (*table) = &eth_lay3;
78 return;
79 invalid:
80 (*off) = 0;
81 (*key) = 0;
82 (*table) = NULL;
85 struct protocol ipv6_hop_by_hop_ops = {
86 .key = 0x0,
87 // .offset = sizeof(struct fragmhdr),
88 .print_full = hop_by_hop,
89 .print_less = hop_by_hop_less,
90 .print_pay_ascii = empty,
91 .print_pay_hex = empty,
92 .print_pay_none = hop_by_hop,
93 .print_all_cstyle = __hex2,
94 .print_all_hex = __hex,
95 .proto_next = hop_by_hop_next,
98 #endif /* HOP_BY_HOP_H */