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 2012 Markus Amend.
6 * Subject to the GPL, version 2.
14 #include <netinet/in.h> /* for ntohs() */
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
19 struct hop_by_hophdr
{
20 uint8_t h_next_header
;
21 uint8_t h_hdr_ext_len
;
22 uint8_t h_hdr_option_type
;
23 } __attribute__((packed
));
25 static inline void hop_by_hop(uint8_t *packet
, size_t len
)
28 struct hop_by_hophdr
*hop_by_hop
= (struct hop_by_hophdr
*) packet
;
30 hdr_ext_len
= (hop_by_hop
->h_hdr_ext_len
+ 1) * 8;
31 if (len
< hdr_ext_len
|| len
< sizeof(struct hop_by_hophdr
))
34 tprintf("\t [ Hop-By-Hop ");
35 tprintf("NextHdr (%u), ", hop_by_hop
->h_next_header
);
36 tprintf("HdrExtLen (%u), ", hdr_ext_len
);
37 tprintf("Opt (%u), ", hop_by_hop
->h_hdr_option_type
);
38 tprintf("Appendix 0x");
39 for (uint8_t i
= sizeof(struct hop_by_hophdr
); i
< hdr_ext_len
; i
++)
40 tprintf("%02x",(uint8_t) packet
[i
]);
44 static inline void hop_by_hop_less(uint8_t *packet
, size_t len
)
47 struct hop_by_hophdr
*hop_by_hop
= (struct hop_by_hophdr
*) packet
;
49 hdr_ext_len
= (hop_by_hop
->h_hdr_ext_len
+ 1) * 8;
50 if (len
< hdr_ext_len
|| len
< sizeof(struct hop_by_hophdr
))
53 tprintf(" Hop-By-Hop Opt %u", hop_by_hop
->h_hdr_option_type
);
56 static inline void hop_by_hop_next(uint8_t *packet
, size_t len
,
57 struct hash_table
**table
,
58 unsigned int *key
, size_t *off
)
61 struct hop_by_hophdr
*hop_by_hop
= (struct hop_by_hophdr
*) packet
;
63 hdr_ext_len
= (hop_by_hop
->h_hdr_ext_len
+ 1) * 8;
64 if (len
< hdr_ext_len
|| len
< sizeof(struct hop_by_hophdr
))
68 (*key
) = hop_by_hop
->h_next_header
;
72 struct protocol ipv6_hop_by_hop_ops
= {
74 .print_full
= hop_by_hop
,
75 .print_less
= hop_by_hop_less
,
76 .print_pay_ascii
= empty
,
77 .print_pay_hex
= empty
,
78 .print_pay_none
= hop_by_hop
,
80 .proto_next
= hop_by_hop_next
,
83 #endif /* HOP_BY_HOP_H */