html: some further minor tweaks on the index page
[netsniff-ng.git] / src / proto_ipv6.h
bloba1568ebefff15f401cfda89e39172f9212f74a12
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Copyright 2010 Emmanuel Roullit.
6 * Subject to the GPL, version 2.
7 */
9 #ifndef IPV6_H
10 #define IPV6_H
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <netinet/in.h> /* for ntohs() */
15 #include <arpa/inet.h> /* for inet_ntop() */
16 #include <asm/byteorder.h>
18 #include "csum.h"
19 #include "proto_struct.h"
20 #include "dissector_eth.h"
23 * IPv6 fixed header
25 * BEWARE, it is incorrect. The first 4 bits of flow_lbl
26 * are glued to priority now, forming "class".
28 struct ipv6hdr {
29 #if defined(__LITTLE_ENDIAN_BITFIELD)
30 __extension__ uint8_t priority:4,
31 version:4;
32 #elif defined(__BIG_ENDIAN_BITFIELD)
33 __extension__ uint8_t version:4,
34 priority:4;
35 #else
36 # error "Please fix <asm/byteorder.h>"
37 #endif
38 uint8_t flow_lbl[3];
39 uint16_t payload_len;
40 uint8_t nexthdr;
41 uint8_t hop_limit;
42 struct in6_addr saddr;
43 struct in6_addr daddr;
44 } __attribute__((packed));
46 static inline void ipv6(uint8_t *packet, size_t len)
48 uint8_t traffic_class;
49 uint32_t flow_label;
50 char src_ip[INET6_ADDRSTRLEN];
51 char dst_ip[INET6_ADDRSTRLEN];
52 struct ipv6hdr *ip = (struct ipv6hdr *) packet;
54 if (len < sizeof(struct ipv6hdr))
55 return;
57 traffic_class = (ip->priority << 4) |
58 ((ip->flow_lbl[0] & 0xF0) >> 4);
59 flow_label = ((ip->flow_lbl[0] & 0x0F) << 8) |
60 (ip->flow_lbl[1] << 4) | ip->flow_lbl[2];
62 inet_ntop(AF_INET6, &ip->saddr, src_ip, sizeof(src_ip));
63 inet_ntop(AF_INET6, &ip->daddr, dst_ip, sizeof(dst_ip));
65 tprintf(" [ IPv6 ");
66 tprintf("Addr (%s => %s), ", src_ip, dst_ip);
67 tprintf("Version (%u), ", ip->version);
68 tprintf("TrafficClass (%u), ", traffic_class);
69 tprintf("FlowLabel (%u), ", flow_label);
70 tprintf("Len (%u), ", ntohs(ip->payload_len));
71 tprintf("NextHdr (%u), ", ip->nexthdr);
72 tprintf("HopLimit (%u)", ip->hop_limit);
73 tprintf(" ]\n");
76 static inline void ipv6_less(uint8_t *packet, size_t len)
78 char src_ip[INET6_ADDRSTRLEN];
79 char dst_ip[INET6_ADDRSTRLEN];
80 struct ipv6hdr *ip = (struct ipv6hdr *) packet;
82 if (len < sizeof(struct ipv6hdr))
83 return;
85 inet_ntop(AF_INET6, &ip->saddr, src_ip, sizeof(src_ip));
86 inet_ntop(AF_INET6, &ip->daddr, dst_ip, sizeof(dst_ip));
88 tprintf(" %s/%s Len %u", src_ip, dst_ip,
89 ntohs(ip->payload_len));
92 static inline void ipv6_next(uint8_t *packet, size_t len,
93 struct hash_table **table,
94 unsigned int *key, size_t *off)
96 struct ipv6hdr *ip = (struct ipv6hdr *) packet;
98 if (len < sizeof(struct ipv6hdr))
99 goto invalid;
101 (*off) = sizeof(struct ipv6hdr);
102 (*key) = ip->nexthdr;
103 (*table) = &eth_lay3;
105 return;
106 invalid:
107 (*off) = 0;
108 (*key) = 0;
109 (*table) = NULL;
112 struct protocol ipv6_ops = {
113 .key = 0x86DD,
114 .offset = sizeof(struct ipv6hdr),
115 .print_full = ipv6,
116 .print_less = ipv6_less,
117 .print_pay_ascii = empty,
118 .print_pay_hex = empty,
119 .print_pay_none = ipv6,
120 .print_all_cstyle = __hex2,
121 .print_all_hex = __hex,
122 .proto_next = ipv6_next,
125 #endif /* IPV6_H */