curve: minor: fix typo in variable
[netsniff-ng.git] / proto_ipv6_dest_opts.c
blobdfdd25685042bf466b3e6813b69e1181fc257f04
1 /*
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
7 */
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <netinet/in.h> /* for ntohs() */
13 #include "proto.h"
14 #include "protos.h"
15 #include "dissector_eth.h"
16 #include "built_in.h"
17 #include "pkt_buff.h"
19 struct dest_optshdr {
20 uint8_t h_next_header;
21 uint8_t hdr_len;
22 } __packed;
25 static void dissect_opt_dest(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_hop_by_hop.h, it needs
30 * dissect_opt(), too.
32 if (*opt_len)
33 tprintf(", Option(s) recognized ");
35 /* If adding dissector reduce opt_len for each using of pkt_pull
36 * to the same size.
40 static void dest_opts(struct pkt_buff *pkt)
42 uint16_t hdr_ext_len;
43 ssize_t opt_len;
44 struct dest_optshdr *dest_ops;
46 dest_ops = (struct dest_optshdr *) pkt_pull(pkt, sizeof(*dest_ops));
47 if (dest_ops == NULL)
48 return;
50 /* Total Header Length in Bytes */
51 hdr_ext_len = (dest_ops->hdr_len + 1) * 8;
52 /* Options length in Bytes */
53 opt_len = hdr_ext_len - sizeof(*dest_ops);
55 tprintf("\t [ Destination Options ");
56 tprintf("NextHdr (%u), ", dest_ops->h_next_header);
57 if (opt_len > pkt_len(pkt) || opt_len < 0) {
58 tprintf("HdrExtLen (%u, %u Bytes, %s)", dest_ops->hdr_len,
59 hdr_ext_len, colorize_start_full(black, red)
60 "invalid" colorize_end());
61 return;
63 tprintf("HdrExtLen (%u, %u Bytes)", dest_ops->hdr_len,
64 hdr_ext_len);
66 dissect_opt_dest(pkt, &opt_len);
68 tprintf(" ]\n");
70 pkt_pull(pkt, opt_len);
71 pkt_set_proto(pkt, &eth_lay3, dest_ops->h_next_header);
74 static void dest_opts_less(struct pkt_buff *pkt)
76 uint16_t hdr_ext_len;
77 ssize_t opt_len;
78 struct dest_optshdr *dest_ops;
80 dest_ops = (struct dest_optshdr *) pkt_pull(pkt, sizeof(*dest_ops));
81 if (dest_ops == NULL)
82 return;
84 /* Total Header Length in Bytes */
85 hdr_ext_len = (dest_ops->hdr_len + 1) * 8;
86 /* Options length in Bytes */
87 opt_len = hdr_ext_len - sizeof(*dest_ops);
88 if (opt_len > pkt_len(pkt) || opt_len < 0)
89 return;
91 tprintf(" Dest Ops");
93 pkt_pull(pkt, opt_len);
94 pkt_set_proto(pkt, &eth_lay3, dest_ops->h_next_header);
97 struct protocol ipv6_dest_opts_ops = {
98 .key = 0x3C,
99 .print_full = dest_opts,
100 .print_less = dest_opts_less,