dissector: if no printing, then don't alloc
[netsniff-ng.git] / src / proto_ipv6_fragm.h
blob43d8596ab5c0e2dc081b5411272e0f8d44fc453a
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 Fragmentation Header described in RFC2460
7 */
9 #ifndef PROTO_IPV6_FRAGM_H
10 #define PROTO_IPV6_FRAGM_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 fragmhdr {
21 uint8_t h_fragm_next_header;
22 uint8_t h_fragm_reserved;
23 uint16_t h_fragm_off_res_M;
24 uint32_t h_fragm_identification;
25 } __packed;
27 static inline void fragm(uint8_t *packet, size_t len)
29 uint16_t off_res_M;
30 struct fragmhdr *fragm = (struct fragmhdr *) packet;
32 if (len < sizeof(struct fragmhdr))
33 return;
35 off_res_M = ntohs(fragm->h_fragm_off_res_M);
37 tprintf("\t [ Fragment ");
38 tprintf("NextHdr (%u), ", fragm->h_fragm_next_header);
39 tprintf("Reserved (%u), ", fragm->h_fragm_reserved);
40 tprintf("Offset (%u), ", off_res_M >> 3);
41 tprintf("Res (%u), ", (off_res_M >> 1) & 0x3);
42 tprintf("M flag (%u), ", off_res_M & 0x1);
43 tprintf("Identification (%u) ", ntohl(fragm->h_fragm_identification));
44 tprintf(" ]\n");
47 static inline void fragm_less(uint8_t *packet, size_t len)
49 uint16_t off_res_M;
50 struct fragmhdr *fragm = (struct fragmhdr *) packet;
52 if (len < sizeof(struct fragmhdr))
53 return;
55 off_res_M = ntohs(fragm->h_fragm_off_res_M);
57 tprintf(" FragmOffs %u", off_res_M >> 3);
60 static inline void fragm_next(uint8_t *packet, size_t len,
61 struct hash_table **table,
62 unsigned int *key, size_t *off)
64 struct fragmhdr *fragm = (struct fragmhdr *) packet;
65 if (len < sizeof(struct fragmhdr))
66 return;
67 (*off) = sizeof(struct fragmhdr);
68 (*key) = fragm->h_fragm_next_header;
69 (*table) = &eth_lay3;
72 struct protocol ipv6_fragm_ops = {
73 .key = 0x2C,
74 .print_full = fragm,
75 .print_less = fragm_less,
76 .proto_next = fragm_next,
79 #endif /* PROTO_IPV6_FRAGM_H */