ring: built_in: fix if cacheline_aligned is not defined
[netsniff-ng.git] / src / proto_ipv6_hop_by_hop.h
blob8e0513448a08c1dee838b07e967b47f8f29b433d
1 /*
2 * IPv6 Hop-By-Hop Header described in RFC2460
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 HOP_BY_HOP_H
10 #define 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"
19 struct hop_by_hophdr {
20 uint8_t h_next_header;
21 uint8_t h_hdr_ext_len;
22 uint8_t h_hdr_option_type;
23 } __attribute__((packed));
25 static inline void hop_by_hop(uint8_t *packet, size_t len)
27 uint8_t hdr_ext_len;
28 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
30 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
31 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
32 return;
34 tprintf("\t [ Hop-By-Hop ");
35 tprintf("NextHdr (%u), ", hop_by_hop->h_next_header);
36 tprintf("HdrExtLen (%u), ", hdr_ext_len);
37 tprintf("Opt (%u), ", hop_by_hop->h_hdr_option_type);
38 tprintf("Appendix 0x");
39 for (uint8_t i = sizeof(struct hop_by_hophdr); i < hdr_ext_len; i++)
40 tprintf("%02x",(uint8_t) packet[i]);
41 tprintf(" ]\n");
44 static inline void hop_by_hop_less(uint8_t *packet, size_t len)
46 uint8_t hdr_ext_len;
47 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
49 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
50 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
51 return;
53 tprintf(" Hop-By-Hop Opt %u", hop_by_hop->h_hdr_option_type);
56 static inline void hop_by_hop_next(uint8_t *packet, size_t len,
57 struct hash_table **table,
58 unsigned int *key, size_t *off)
60 uint8_t hdr_ext_len;
61 struct hop_by_hophdr *hop_by_hop = (struct hop_by_hophdr *) packet;
63 hdr_ext_len = (hop_by_hop->h_hdr_ext_len + 1) * 8;
64 if (len < hdr_ext_len || len < sizeof(struct hop_by_hophdr))
65 return;
67 (*off) = hdr_ext_len;
68 (*key) = hop_by_hop->h_next_header;
69 (*table) = &eth_lay3;
72 struct protocol ipv6_hop_by_hop_ops = {
73 .key = 0x0,
74 .print_full = hop_by_hop,
75 .print_less = hop_by_hop_less,
76 .print_pay_ascii = empty,
77 .print_pay_hex = empty,
78 .print_pay_none = hop_by_hop,
79 .print_all_hex = hex,
80 .proto_next = hop_by_hop_next,
83 #endif /* HOP_BY_HOP_H */