xio: added create empty file routine
[netsniff-ng.git] / src / proto_ipv6.h
blobe93e5dda1b094e1ab2019280c68621213e94c680
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"
21 #include "pkt_buff.h"
24 * IPv6 fixed header
26 * BEWARE, it is incorrect. The first 4 bits of flow_lbl
27 * are glued to priority now, forming "class".
29 struct ipv6hdr {
30 #if defined(__LITTLE_ENDIAN_BITFIELD)
31 __extension__ uint8_t priority:4,
32 version:4;
33 #elif defined(__BIG_ENDIAN_BITFIELD)
34 __extension__ uint8_t version:4,
35 priority:4;
36 #else
37 # error "Please fix <asm/byteorder.h>"
38 #endif
39 uint8_t flow_lbl[3];
40 uint16_t payload_len;
41 uint8_t nexthdr;
42 uint8_t hop_limit;
43 struct in6_addr saddr;
44 struct in6_addr daddr;
45 } __attribute__((packed));
47 static inline void ipv6(struct pkt_buff *pkt)
49 uint8_t traffic_class;
50 uint32_t flow_label;
51 char src_ip[INET6_ADDRSTRLEN];
52 char dst_ip[INET6_ADDRSTRLEN];
53 struct ipv6hdr *ip = (struct ipv6hdr *) pkt_pull(pkt, sizeof(*ip));
55 if (ip == NULL)
56 return;
58 traffic_class = (ip->priority << 4) |
59 ((ip->flow_lbl[0] & 0xF0) >> 4);
60 flow_label = ((ip->flow_lbl[0] & 0x0F) << 8) |
61 (ip->flow_lbl[1] << 4) | ip->flow_lbl[2];
63 inet_ntop(AF_INET6, &ip->saddr, src_ip, sizeof(src_ip));
64 inet_ntop(AF_INET6, &ip->daddr, dst_ip, sizeof(dst_ip));
66 tprintf(" [ IPv6 ");
67 tprintf("Addr (%s => %s), ", src_ip, dst_ip);
68 tprintf("Version (%u), ", ip->version);
69 tprintf("TrafficClass (%u), ", traffic_class);
70 tprintf("FlowLabel (%u), ", flow_label);
71 tprintf("Len (%u), ", ntohs(ip->payload_len));
72 tprintf("NextHdr (%u), ", ip->nexthdr);
73 tprintf("HopLimit (%u)", ip->hop_limit);
74 tprintf(" ]\n");
76 pkt_set_proto(pkt, &eth_lay3, ip->nexthdr);
79 static inline void ipv6_less(struct pkt_buff *pkt)
81 char src_ip[INET6_ADDRSTRLEN];
82 char dst_ip[INET6_ADDRSTRLEN];
83 struct ipv6hdr *ip = (struct ipv6hdr *) pkt_pull(pkt, sizeof(*ip));
85 if (ip == NULL)
86 return;
88 inet_ntop(AF_INET6, &ip->saddr, src_ip, sizeof(src_ip));
89 inet_ntop(AF_INET6, &ip->daddr, dst_ip, sizeof(dst_ip));
91 tprintf(" %s/%s Len %u", src_ip, dst_ip,
92 ntohs(ip->payload_len));
94 pkt_set_proto(pkt, &eth_lay3, ip->nexthdr);
97 struct protocol ipv6_ops = {
98 .key = 0x86DD,
99 .print_full = ipv6,
100 .print_less = ipv6_less,
103 #endif /* IPV6_H */