dissector: if no printing, then don't alloc
[netsniff-ng.git] / src / proto_ipv6_dest_opts.h
blob25817cbbbb2a3b0687d85c9dbd9ea48c784db545
1 /*
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 Destination Options Header described in RFC2460
7 */
9 #ifndef PROTO_IPV6_DEST_OPTS_H
10 #define PROTO_IPV6_DEST_OPTS_H
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <netinet/in.h> /* for ntohs() */
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
18 #include "built_in.h"
20 struct dest_optshdr {
21 uint8_t h_next_header;
22 uint8_t hdr_len;
23 } __packed;
26 static inline void dissect_opt(struct pkt_buff *pkt, uint8_t *opt_len)
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
31 * dissect_opt(), too.
33 if (*opt_len)
34 tprintf(", Option(s) recognized ");
36 /* If adding dissector reduce opt_len for each using of pkt_pull
37 * to the same size.
41 static inline void dest_opts(struct pkt_buff *pkt)
43 uint8_t hdr_ext_len, opt_len;
44 struct dest_optshdr *dest_ops;
46 dest_ops = (struct dest_optshdr *) pkt_pull(pkt, sizeof(*dest_ops));
48 /* Total Header Length in Bytes */
49 hdr_ext_len = (dest_ops->hdr_len + 1) * 8;
50 /* Options length in Bytes */
51 opt_len = hdr_ext_len - sizeof(*dest_ops);
52 if (dest_ops == NULL || opt_len > pkt_len(pkt))
53 return;
55 tprintf("\t [ Destination Options ");
56 tprintf("NextHdr (%u), ", dest_ops->h_next_header);
57 tprintf("HdrExtLen (%u, %u Bytes)", dest_ops->hdr_len,
58 opt_len);
60 dissect_opt(pkt, &opt_len);
62 tprintf(" ]\n");
64 pkt_pull(pkt, opt_len);
65 pkt_set_proto(pkt, &eth_lay3, dest_ops->h_next_header);
68 static inline void dest_opts_less(struct pkt_buff *pkt)
70 uint8_t hdr_ext_len, opt_len;
71 struct dest_optshdr *dest_ops;
73 dest_ops = (struct dest_optshdr *) pkt_pull(pkt, sizeof(*dest_ops));
75 /* Total Header Length in Bytes */
76 hdr_ext_len = (dest_ops->hdr_len + 1) * 8;
77 /* Options length in Bytes */
78 opt_len = hdr_ext_len - sizeof(*dest_ops);
79 if (dest_ops == NULL || opt_len > pkt_len(pkt))
80 return;
82 tprintf(" Dest Ops");
84 pkt_pull(pkt, opt_len);
85 pkt_set_proto(pkt, &eth_lay3, dest_ops->h_next_header);
88 struct protocol ipv6_dest_opts_ops = {
89 .key = 0x3C,
90 .print_full = dest_opts,
91 .print_less = dest_opts_less,
94 #endif /* PROTO_IPV6_DEST_OPTS_H */