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.
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
)
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
))
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
]);
47 static inline void hop_by_hop_less(uint8_t *packet
, size_t 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
))
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
)
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
))
75 (*key
) = hop_by_hop
->h_next_header
;
85 struct protocol ipv6_hop_by_hop_ops
= {
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 */