2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>
4 * Subject to the GPL, version 2.
6 * IPv6 Hop-By-Hop Header described in RFC2460
9 #ifndef PROTO_IPV6_HOP_BY_HOP_H
10 #define PROTO_IPV6_HOP_BY_HOP_H
14 #include <netinet/in.h> /* for ntohs() */
16 #include "proto_struct.h"
17 #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
;
26 static inline void hop_by_hop(uint8_t *packet
, size_t len
)
29 struct hop_by_hophdr
*hop_by_hop
= (struct hop_by_hophdr
*) packet
;
31 hdr_ext_len
= (hop_by_hop
->h_hdr_ext_len
+ 1) * 8;
32 if (len
< hdr_ext_len
|| len
< sizeof(struct hop_by_hophdr
))
35 tprintf("\t [ Hop-By-Hop ");
36 tprintf("NextHdr (%u), ", hop_by_hop
->h_next_header
);
37 tprintf("HdrExtLen (%u), ", hdr_ext_len
);
38 tprintf("Opt (%u), ", hop_by_hop
->h_hdr_option_type
);
39 tprintf("Appendix 0x");
40 for (uint8_t i
= sizeof(struct hop_by_hophdr
); i
< hdr_ext_len
; i
++)
41 tprintf("%02x",(uint8_t) packet
[i
]);
45 static inline void hop_by_hop_less(uint8_t *packet
, size_t len
)
48 struct hop_by_hophdr
*hop_by_hop
= (struct hop_by_hophdr
*) packet
;
50 hdr_ext_len
= (hop_by_hop
->h_hdr_ext_len
+ 1) * 8;
51 if (len
< hdr_ext_len
|| len
< sizeof(struct hop_by_hophdr
))
54 tprintf(" Hop-By-Hop Opt %u", hop_by_hop
->h_hdr_option_type
);
57 static inline void hop_by_hop_next(uint8_t *packet
, size_t len
,
58 struct hash_table
**table
,
59 unsigned int *key
, size_t *off
)
62 struct hop_by_hophdr
*hop_by_hop
= (struct hop_by_hophdr
*) packet
;
64 hdr_ext_len
= (hop_by_hop
->h_hdr_ext_len
+ 1) * 8;
65 if (len
< hdr_ext_len
|| len
< sizeof(struct hop_by_hophdr
))
69 (*key
) = hop_by_hop
->h_next_header
;
73 struct protocol ipv6_hop_by_hop_ops
= {
75 .print_full
= hop_by_hop
,
76 .print_less
= hop_by_hop_less
,
77 .proto_next
= hop_by_hop_next
,
80 #endif /* PROTO_IPV6_HOP_BY_HOP_H */