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.
11 #include <netinet/in.h> /* for ntohs() */
12 #include <arpa/inet.h> /* for inet_ntop() */
17 #include "dissector_eth.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
;
28 char src_ip
[INET6_ADDRSTRLEN
];
29 char dst_ip
[INET6_ADDRSTRLEN
];
30 struct ipv6hdr
*ip
= (struct ipv6hdr
*) pkt_pull(pkt
, sizeof(*ip
));
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
));
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
);
53 pkt_set_proto(pkt
, ð_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
));
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
, ð_lay3
, ip
->nexthdr
);
74 struct protocol ipv6_ops
= {
77 .print_less
= ipv6_less
,
80 EXPORT_SYMBOL(ipv6_ops
);