proto_ipv6_mobility_hdr.h: Headerfixing
[netsniff-ng.git] / src / proto_ipv6_hop_by_hop.h
blob6ff71f5631be4ed73ab8551d455bea3672869a1a
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 Hop-By-Hop Header described in RFC2460
7 */
9 #ifndef PROTO_IPV6_HOP_BY_HOP_H
10 #define PROTO_IPV6_HOP_BY_HOP_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 hop_by_hophdr {
21 uint8_t h_next_header;
22 uint8_t h_hdr_ext_len;
23 uint8_t h_hdr_option_type;
24 } __packed;
26 static inline void hop_by_hop(uint8_t *packet, size_t len)
28 uint8_t hdr_ext_len;
29 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
31 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
32 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
33 return;
35 tprintf("\t [ Hop-By-Hop ");
36 tprintf("NextHdr (%u), ", hop_by_hop->h_next_header);
37 tprintf("HdrExtLen (%u), ", hdr_ext_len);
38 tprintf("Opt (%u), ", hop_by_hop->h_hdr_option_type);
39 tprintf("Appendix 0x");
40 for (uint8_t i = sizeof(struct hop_by_hophdr); i < hdr_ext_len; i++)
41 tprintf("%02x",(uint8_t) packet[i]);
42 tprintf(" ]\n");
45 static inline void hop_by_hop_less(uint8_t *packet, size_t len)
47 uint8_t hdr_ext_len;
48 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
50 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
51 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
52 return;
54 tprintf(" Hop-By-Hop Opt %u", hop_by_hop->h_hdr_option_type);
57 static inline void hop_by_hop_next(uint8_t *packet, size_t len,
58 struct hash_table **table,
59 unsigned int *key, size_t *off)
61 uint8_t hdr_ext_len;
62 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
64 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
65 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
66 return;
68 (*off) = hdr_ext_len;
69 (*key) = hop_by_hop->h_next_header;
70 (*table) = &eth_lay3;
73 struct protocol ipv6_hop_by_hop_ops = {
74 .key = 0x0,
75 .print_full = hop_by_hop,
76 .print_less = hop_by_hop_less,
77 .proto_next = hop_by_hop_next,
80 #endif /* PROTO_IPV6_HOP_BY_HOP_H */