dissector_fuzz: removed printing opts to make for usage with diff
[netsniff-ng.git] / src / proto_ipv6.h
blob9ce90fc541457dc404fa9e4e75e60b19e8f339fc
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 PROTO_IPV6_H
10 #define PROTO_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"
21 #include "pkt_buff.h"
22 #include "built_in.h"
25 * IPv6 fixed header
27 * BEWARE, it is incorrect. The first 4 bits of flow_lbl
28 * are glued to priority now, forming "class".
30 struct ipv6hdr {
31 #if defined(__LITTLE_ENDIAN_BITFIELD)
32 __extension__ uint8_t priority:4,
33 version:4;
34 #elif defined(__BIG_ENDIAN_BITFIELD)
35 __extension__ uint8_t version:4,
36 priority:4;
37 #else
38 # error "Please fix <asm/byteorder.h>"
39 #endif
40 uint8_t flow_lbl[3];
41 uint16_t payload_len;
42 uint8_t nexthdr;
43 uint8_t hop_limit;
44 struct in6_addr saddr;
45 struct in6_addr daddr;
46 } __packed;
48 static inline void ipv6(struct pkt_buff *pkt)
50 uint8_t traffic_class;
51 uint32_t flow_label;
52 char src_ip[INET6_ADDRSTRLEN];
53 char dst_ip[INET6_ADDRSTRLEN];
54 struct ipv6hdr *ip = (struct ipv6hdr *) pkt_pull(pkt, sizeof(*ip));
56 if (ip == NULL)
57 return;
59 traffic_class = (ip->priority << 4) |
60 ((ip->flow_lbl[0] & 0xF0) >> 4);
61 flow_label = ((ip->flow_lbl[0] & 0x0F) << 8) |
62 (ip->flow_lbl[1] << 4) | ip->flow_lbl[2];
64 inet_ntop(AF_INET6, &ip->saddr, src_ip, sizeof(src_ip));
65 inet_ntop(AF_INET6, &ip->daddr, dst_ip, sizeof(dst_ip));
67 tprintf(" [ IPv6 ");
68 tprintf("Addr (%s => %s), ", src_ip, dst_ip);
69 tprintf("Version (%u), ", ip->version);
70 tprintf("TrafficClass (%u), ", traffic_class);
71 tprintf("FlowLabel (%u), ", flow_label);
72 tprintf("Len (%u), ", ntohs(ip->payload_len));
73 tprintf("NextHdr (%u), ", ip->nexthdr);
74 tprintf("HopLimit (%u)", ip->hop_limit);
75 tprintf(" ]\n");
77 pkt_set_proto(pkt, &eth_lay3, ip->nexthdr);
80 static inline void ipv6_less(struct pkt_buff *pkt)
82 char src_ip[INET6_ADDRSTRLEN];
83 char dst_ip[INET6_ADDRSTRLEN];
84 struct ipv6hdr *ip = (struct ipv6hdr *) pkt_pull(pkt, sizeof(*ip));
86 if (ip == NULL)
87 return;
89 inet_ntop(AF_INET6, &ip->saddr, src_ip, sizeof(src_ip));
90 inet_ntop(AF_INET6, &ip->daddr, dst_ip, sizeof(dst_ip));
92 tprintf(" %s/%s Len %u", src_ip, dst_ip,
93 ntohs(ip->payload_len));
95 pkt_set_proto(pkt, &eth_lay3, ip->nexthdr);
98 struct protocol ipv6_ops = {
99 .key = 0x86DD,
100 .print_full = ipv6,
101 .print_less = ipv6_less,
104 #endif /* PROTO_IPV6_H */