2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>, Deutsche Flugsicherung GmbH
4 * Subject to the GPL, version 2.
6 * IPv6 Destination Options Header described in RFC2460
11 #include <netinet/in.h> /* for ntohs() */
15 #include "dissector_eth.h"
20 uint8_t h_next_header
;
25 static void dissect_opt_dest(struct pkt_buff
*pkt __maybe_unused
,
28 /* Have to been upgraded.
29 * http://tools.ietf.org/html/rfc2460#section-4.2
30 * Look also for proto_ipv6_hop_by_hop.h, it needs
34 tprintf(", Option(s) recognized ");
36 /* If adding dissector reduce opt_len for each using of pkt_pull
41 static void dest_opts(struct pkt_buff
*pkt
)
45 struct dest_optshdr
*dest_ops
;
47 dest_ops
= (struct dest_optshdr
*) pkt_pull(pkt
, sizeof(*dest_ops
));
51 /* Total Header Length in Bytes */
52 hdr_ext_len
= (dest_ops
->hdr_len
+ 1) * 8;
53 /* Options length in Bytes */
54 opt_len
= hdr_ext_len
- sizeof(*dest_ops
);
56 tprintf("\t [ Destination Options ");
57 tprintf("NextHdr (%u), ", dest_ops
->h_next_header
);
58 if (opt_len
> pkt_len(pkt
) || opt_len
< 0) {
59 tprintf("HdrExtLen (%u, %u Bytes, %s)", dest_ops
->hdr_len
,
60 hdr_ext_len
, colorize_start_full(black
, red
)
61 "invalid" colorize_end());
64 tprintf("HdrExtLen (%u, %u Bytes)", dest_ops
->hdr_len
,
67 dissect_opt_dest(pkt
, &opt_len
);
71 pkt_pull(pkt
, opt_len
);
72 pkt_set_proto(pkt
, ð_lay3
, dest_ops
->h_next_header
);
75 static void dest_opts_less(struct pkt_buff
*pkt
)
79 struct dest_optshdr
*dest_ops
;
81 dest_ops
= (struct dest_optshdr
*) pkt_pull(pkt
, sizeof(*dest_ops
));
85 /* Total Header Length in Bytes */
86 hdr_ext_len
= (dest_ops
->hdr_len
+ 1) * 8;
87 /* Options length in Bytes */
88 opt_len
= hdr_ext_len
- sizeof(*dest_ops
);
89 if (opt_len
> pkt_len(pkt
) || opt_len
< 0)
94 pkt_pull(pkt
, opt_len
);
95 pkt_set_proto(pkt
, ð_lay3
, dest_ops
->h_next_header
);
98 struct protocol ipv6_dest_opts_ops
= {
100 .print_full
= dest_opts
,
101 .print_less
= dest_opts_less
,