Merge pull request #59 from electronjoe/graceful-SIGTERM-handling
[netsniff-ng-old.git] / proto_ipv6_fragm.c
blob568a89703d9ee88a410dcdd3f91f132ccdf8ae49
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 Fragmentation 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 fragmhdr {
20 uint8_t h_fragm_next_header;
21 uint8_t h_fragm_reserved;
22 uint16_t h_fragm_off_res_M;
23 uint32_t h_fragm_identification;
24 } __packed;
26 static void fragm(struct pkt_buff *pkt)
28 uint16_t off_res_M;
29 struct fragmhdr *fragm_ops;
31 fragm_ops = (struct fragmhdr *) pkt_pull(pkt, sizeof(*fragm_ops));
32 if (fragm_ops == NULL)
33 return;
35 off_res_M = ntohs(fragm_ops->h_fragm_off_res_M);
37 tprintf("\t [ Fragment ");
38 tprintf("NextHdr (%u), ", fragm_ops->h_fragm_next_header);
39 tprintf("Reserved (%u), ", fragm_ops->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)",
44 ntohl(fragm_ops->h_fragm_identification));
45 tprintf(" ]\n");
47 pkt_set_proto(pkt, &eth_lay3, fragm_ops->h_fragm_next_header);
50 static void fragm_less(struct pkt_buff *pkt)
52 uint16_t off_res_M;
53 struct fragmhdr *fragm_ops;
55 fragm_ops = (struct fragmhdr *) pkt_pull(pkt, sizeof(*fragm_ops));
56 if (fragm_ops == NULL)
57 return;
59 off_res_M = ntohs(fragm_ops->h_fragm_off_res_M);
61 tprintf(" FragmOffs %u", off_res_M >> 3);
63 pkt_set_proto(pkt, &eth_lay3, fragm_ops->h_fragm_next_header);
66 struct protocol ipv6_fragm_ops = {
67 .key = 0x2C,
68 .print_full = fragm,
69 .print_less = fragm_less,