xio: added create empty file routine
[netsniff-ng.git] / src / proto_ipv6_routing.h
blob5fccdcc31f56afa708abd32571196c3798503bbd
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 Routing Header described in RFC2460
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\t Address: ");
46 tprintf("%s", inet_ntop(AF_INET6, &packet[i],
47 address, sizeof(address)));
49 } else {
50 tprintf("Appendix 0x");
51 for (uint8_t i = sizeof(struct routinghdr);
52 i < hdr_ext_len; i++)
53 tprintf("%02x",(uint8_t) packet[i]);
55 tprintf(" ]\n");
58 static inline void routing_less(uint8_t *packet, size_t len)
60 uint8_t hdr_ext_len;
61 struct routinghdr *routing = (struct routinghdr *) packet;
63 hdr_ext_len = (routing->h_hdr_ext_len + 1) * 8;
64 if (len < hdr_ext_len || len < sizeof(struct routinghdr))
65 return;
67 tprintf(" Routing Type %u", routing->h_routing_type);
70 static inline void routing_next(uint8_t *packet, size_t len,
71 struct hash_table **table,
72 unsigned int *key, size_t *off)
74 uint8_t hdr_ext_len;
75 struct routinghdr *routing = (struct routinghdr *) packet;
77 hdr_ext_len = (routing->h_hdr_ext_len + 1) * 8;
78 if (len < hdr_ext_len || len < sizeof(struct routinghdr))
79 return;
81 (*off) = hdr_ext_len;
82 (*key) = routing->h_next_header;
83 (*table) = &eth_lay3;
86 struct protocol ipv6_routing_ops = {
87 .key = 0x2B,
88 .print_full = routing,
89 .print_less = routing_less,
90 .proto_next = routing_next,
93 #endif /* ROUTING_H */