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
;
25 static inline void dissect_opt_hop (struct pkt_buff
*pkt
, ssize_t
*opt_len
)
27 /* Have to been upgraded.
28 * http://tools.ietf.org/html/rfc2460#section-4.2
29 * Look also for proto_ipv6_dest_opts.h, it needs
33 tprintf(", Option(s) recognized ");
35 /* If adding dissector reduce opt_len for each using of pkt_pull
40 static inline void hop_by_hop(struct pkt_buff
*pkt
)
44 struct hop_by_hophdr
*hop_ops
;
46 hop_ops
= (struct hop_by_hophdr
*) pkt_pull(pkt
, sizeof(*hop_ops
));
48 /* Total Header Length in Bytes */
49 hdr_ext_len
= (hop_ops
->hdr_len
+ 1) * 8;
50 /* Options length in Bytes */
51 opt_len
= hdr_ext_len
- sizeof(*hop_ops
);
55 tprintf("\t [ Hop-by-Hop Options ");
56 tprintf("NextHdr (%u), ", hop_ops
->h_next_header
);
57 if (opt_len
> pkt_len(pkt
) || opt_len
< 0){
58 tprintf("HdrExtLen (%u, %u Bytes, %s)", hop_ops
->hdr_len
,
59 hdr_ext_len
, colorize_start_full(black
, red
)
60 "invalid" colorize_end());
63 tprintf("HdrExtLen (%u, %u Bytes)", hop_ops
->hdr_len
,
66 dissect_opt_hop(pkt
, &opt_len
);
70 pkt_pull(pkt
, opt_len
);
71 pkt_set_proto(pkt
, ð_lay3
, hop_ops
->h_next_header
);
74 static inline void hop_by_hop_less(struct pkt_buff
*pkt
)
78 struct hop_by_hophdr
*hop_ops
;
80 hop_ops
= (struct hop_by_hophdr
*) pkt_pull(pkt
, sizeof(*hop_ops
));
82 /* Total Header Length in Bytes */
83 hdr_ext_len
= (hop_ops
->hdr_len
+ 1) * 8;
84 /* Options length in Bytes */
85 opt_len
= hdr_ext_len
- sizeof(*hop_ops
);
86 if (hop_ops
== NULL
|| opt_len
> pkt_len(pkt
) || opt_len
< 0)
91 pkt_pull(pkt
, opt_len
);
92 pkt_set_proto(pkt
, ð_lay3
, hop_ops
->h_next_header
);
95 struct protocol ipv6_hop_by_hop_ops
= {
97 .print_full
= hop_by_hop
,
98 .print_less
= hop_by_hop_less
,
101 #endif /* PROTO_IPV6_HOP_BY_HOP_H */