trafgen: add standard include for cpp
[netsniff-ng.git] / proto_ipv6.c
blob3de61fb2dee3ac990a11459904f98582bea6a538
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 #include <stdio.h>
10 #include <stdint.h>
11 #include <netinet/in.h> /* for ntohs() */
12 #include <arpa/inet.h> /* for inet_ntop() */
14 #include "proto.h"
15 #include "protos.h"
16 #include "csum.h"
17 #include "dissector_eth.h"
18 #include "ipv6.h"
19 #include "pkt_buff.h"
21 extern void ipv6(struct pkt_buff *pkt);
22 extern void ipv6_less(struct pkt_buff *pkt);
24 void ipv6(struct pkt_buff *pkt)
26 uint8_t traffic_class;
27 uint32_t flow_label;
28 char src_ip[INET6_ADDRSTRLEN];
29 char dst_ip[INET6_ADDRSTRLEN];
30 struct ipv6hdr *ip = (struct ipv6hdr *) pkt_pull(pkt, sizeof(*ip));
32 if (ip == NULL)
33 return;
35 traffic_class = (ip->priority << 4) |
36 ((ip->flow_lbl[0] & 0xF0) >> 4);
37 flow_label = ((ip->flow_lbl[0] & 0x0F) << 8) |
38 (ip->flow_lbl[1] << 4) | ip->flow_lbl[2];
40 inet_ntop(AF_INET6, &ip->saddr, src_ip, sizeof(src_ip));
41 inet_ntop(AF_INET6, &ip->daddr, dst_ip, sizeof(dst_ip));
43 tprintf(" [ IPv6 ");
44 tprintf("Addr (%s => %s), ", src_ip, dst_ip);
45 tprintf("Version (%u), ", ip->version);
46 tprintf("TrafficClass (%u), ", traffic_class);
47 tprintf("FlowLabel (%u), ", flow_label);
48 tprintf("Len (%u), ", ntohs(ip->payload_len));
49 tprintf("NextHdr (%u), ", ip->nexthdr);
50 tprintf("HopLimit (%u)", ip->hop_limit);
51 tprintf(" ]\n");
53 pkt_set_proto(pkt, &eth_lay3, ip->nexthdr);
56 void ipv6_less(struct pkt_buff *pkt)
58 char src_ip[INET6_ADDRSTRLEN];
59 char dst_ip[INET6_ADDRSTRLEN];
60 struct ipv6hdr *ip = (struct ipv6hdr *) pkt_pull(pkt, sizeof(*ip));
62 if (ip == NULL)
63 return;
65 inet_ntop(AF_INET6, &ip->saddr, src_ip, sizeof(src_ip));
66 inet_ntop(AF_INET6, &ip->daddr, dst_ip, sizeof(dst_ip));
68 tprintf(" %s/%s Len %u", src_ip, dst_ip,
69 ntohs(ip->payload_len));
71 pkt_set_proto(pkt, &eth_lay3, ip->nexthdr);
74 struct protocol ipv6_ops = {
75 .key = 0x86DD,
76 .print_full = ipv6,
77 .print_less = ipv6_less,