dissector: simplified code in dissector, removed duplicate code
[netsniff-ng.git] / src / proto_ipv6_mobility_hdr.h
blob86d0db680555e54bae9a882a7fcfe470ef36a448
1 /*
2 * IPv6 Mobility Header described in RFC6275
3 * programmed by Markus Amend 2012 as a contribution to
4 * netsniff-ng - the packet sniffing beast
5 * Copyright 2012 Markus Amend.
6 * Subject to the GPL, version 2.
7 */
9 #ifndef MOBILITY_HEADER_H
10 #define MOBILITY_HEADER_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"
19 struct mobilityhdr {
20 uint8_t h_next_header;
21 uint8_t h_hdr_ext_len;
22 uint8_t h_MH_type;
23 uint8_t h_reserved;
24 uint16_t h_checksum;
25 } __attribute__((packed));
27 static inline void mobility(uint8_t *packet, size_t len)
29 uint8_t hdr_ext_len;
30 struct mobilityhdr *mobility = (struct mobilityhdr *) packet;
32 hdr_ext_len = (mobility->h_hdr_ext_len + 1) * 8;
33 if (len < hdr_ext_len || len < sizeof(struct mobilityhdr))
34 return;
36 tprintf("\t [ Mobility Header ");
37 tprintf("NextHdr (%u), ", mobility->h_next_header);
38 tprintf("HdrLen (%u), ", hdr_ext_len);
39 tprintf("MH (%u), ", mobility->h_MH_type);
40 tprintf("Res (0x%x), ", mobility->h_reserved);
41 tprintf("Chk (0x%x), ", ntohs(mobility->h_checksum));
42 tprintf("Appendix 0x");
43 for (uint8_t i = sizeof(struct mobilityhdr); i < hdr_ext_len; i++)
44 tprintf("%02x",(uint8_t) packet[i]);
45 tprintf(" ]\n");
48 static inline void mobility_less(uint8_t *packet, size_t len)
50 uint8_t hdr_ext_len;
51 struct mobilityhdr *mobility = (struct mobilityhdr *) packet;
53 hdr_ext_len = (mobility->h_hdr_ext_len + 1) * 8;
54 if (len < hdr_ext_len || len < sizeof(struct mobilityhdr))
55 return;
57 tprintf(" MH Type %u", mobility->h_MH_type);
60 static inline void mobility_next(uint8_t *packet, size_t len,
61 struct hash_table **table,
62 unsigned int *key, size_t *off)
64 uint8_t hdr_ext_len;
65 struct mobilityhdr *mobility = (struct mobilityhdr *) packet;
67 hdr_ext_len = (mobility->h_hdr_ext_len + 1) * 8;
68 if (len < hdr_ext_len || len < sizeof(struct mobilityhdr))
69 return;
71 (*off) = hdr_ext_len;
72 (*key) = mobility->h_next_header;
73 (*table) = &eth_lay3;
76 struct protocol ipv6_mobility_hdr_ops = {
77 .key = 0x87,
78 .print_full = mobility,
79 .print_less = mobility_less,
80 .print_pay_ascii = empty,
81 .print_pay_hex = empty,
82 .print_pay_none = mobility,
83 .print_all_hex = hex,
84 .proto_next = mobility_next,
87 #endif /* MOBILITY_HEADER_H */