proto_ipv6_routing: removed GCC overflow warning of loop counter
[netsniff-ng.git] / src / proto_ipv6_routing.h
bloba666bbc912f1951a574be3d9d48b4a5f6b79fc10
1 /*
2 * IPv6 Routing 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 ROUTING_H
10 #define ROUTING_H
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <netinet/in.h> /* for ntohs() */
15 #include <arpa/inet.h> /* for inet_ntop() */
17 #include "proto_struct.h"
18 #include "dissector_eth.h"
20 struct routinghdr {
21 uint8_t h_next_header;
22 uint8_t h_hdr_ext_len;
23 uint8_t h_routing_type;
24 uint8_t h_segments_left;
25 } __attribute__((packed));
27 static inline void routing(uint8_t *packet, size_t len)
29 uint8_t hdr_ext_len;
30 struct routinghdr *routing = (struct routinghdr *) packet;
32 hdr_ext_len = (routing->h_hdr_ext_len + 1) * 8;
33 if (len < hdr_ext_len || len < sizeof(struct routinghdr))
34 return;
36 tprintf("\t [ Routing ");
37 tprintf("NextHdr (%u), ", routing->h_next_header);
38 tprintf("HdrExtLen (%u), ", hdr_ext_len);
39 tprintf("Type (%u), ", routing->h_routing_type);
40 tprintf("Left (%u), ", routing->h_segments_left);
41 if(routing->h_routing_type == 0) {
42 char address[INET6_ADDRSTRLEN];
43 for (int i = sizeof(struct routinghdr) + 4;
44 i < hdr_ext_len; i += 16) {
45 tprintf("\n\tAdress: ");
46 inet_ntop(AF_INET6, &packet[i], address,
47 sizeof(address));
48 tprintf("%s %u", address ,INET6_ADDRSTRLEN);
50 } else {
51 tprintf("Appendix 0x");
52 for (uint8_t i = sizeof(struct routinghdr);
53 i < hdr_ext_len; i++)
54 tprintf("%02x",(uint8_t) packet[i]);
56 tprintf(" ]\n");
59 static inline void routing_less(uint8_t *packet, size_t len)
61 uint8_t hdr_ext_len;
62 struct routinghdr *routing = (struct routinghdr *) packet;
64 hdr_ext_len = (routing->h_hdr_ext_len + 1) * 8;
65 if (len < hdr_ext_len || len < sizeof(struct routinghdr))
66 return;
68 tprintf(" Routing Type %u", routing->h_routing_type);
71 static inline void routing_next(uint8_t *packet, size_t len,
72 struct hash_table **table,
73 unsigned int *key, size_t *off)
75 uint8_t hdr_ext_len;
76 struct routinghdr *routing = (struct routinghdr *) packet;
78 hdr_ext_len = (routing->h_hdr_ext_len + 1) * 8;
79 if (len < hdr_ext_len || len < sizeof(struct routinghdr))
80 goto invalid;
82 (*off) = hdr_ext_len;
83 (*key) = routing->h_next_header;
84 (*table) = &eth_lay3;
85 return;
86 invalid:
87 (*off) = 0;
88 (*key) = 0;
89 (*table) = NULL;
92 struct protocol ipv6_routing_ops = {
93 .key = 0x2B,
94 .print_full = routing,
95 .print_less = routing_less,
96 .print_pay_ascii = empty,
97 .print_pay_hex = empty,
98 .print_pay_none = routing,
99 .print_all_cstyle = __hex2,
100 .print_all_hex = __hex,
101 .proto_next = routing_next,
104 #endif /* ROUTING_H */