netsniff-ng v0.6.7
[netsniff-ng.git] / proto_ipv6_fragm.c
blob43c0f2008850794f7a0e00215ed160e721c7ece0
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 "dissector_eth.h"
15 #include "built_in.h"
16 #include "pkt_buff.h"
18 struct fragmhdr {
19 uint8_t h_fragm_next_header;
20 uint8_t h_fragm_reserved;
21 uint16_t h_fragm_off_res_M;
22 uint32_t h_fragm_identification;
23 } __packed;
25 static void fragm(struct pkt_buff *pkt)
27 uint16_t off_res_M;
28 struct fragmhdr *fragm_ops;
30 fragm_ops = (struct fragmhdr *) pkt_pull(pkt, sizeof(*fragm_ops));
31 if (fragm_ops == NULL)
32 return;
34 off_res_M = ntohs(fragm_ops->h_fragm_off_res_M);
36 tprintf("\t [ Fragment ");
37 tprintf("NextHdr (%u), ", fragm_ops->h_fragm_next_header);
38 tprintf("Reserved (%u), ", fragm_ops->h_fragm_reserved);
39 tprintf("Offset (%u), ", off_res_M >> 3);
40 tprintf("Res (%u), ", (off_res_M >> 1) & 0x3);
41 tprintf("M flag (%u), ", off_res_M & 0x1);
42 tprintf("Identification (%u)",
43 ntohl(fragm_ops->h_fragm_identification));
44 tprintf(" ]\n");
46 pkt_set_dissector(pkt, &eth_lay3, fragm_ops->h_fragm_next_header);
49 static void fragm_less(struct pkt_buff *pkt)
51 uint16_t off_res_M;
52 struct fragmhdr *fragm_ops;
54 fragm_ops = (struct fragmhdr *) pkt_pull(pkt, sizeof(*fragm_ops));
55 if (fragm_ops == NULL)
56 return;
58 off_res_M = ntohs(fragm_ops->h_fragm_off_res_M);
60 tprintf(" FragmOffs %u", off_res_M >> 3);
62 pkt_set_dissector(pkt, &eth_lay3, fragm_ops->h_fragm_next_header);
65 struct protocol ipv6_fragm_ops = {
66 .key = 0x2C,
67 .print_full = fragm,
68 .print_less = fragm_less,