2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Copyright 2010 Emmanuel Roullit.
5 * Subject to the GPL, version 2.
10 #include <netinet/in.h> /* for ntohs() */
11 #include <arpa/inet.h> /* for inet_ntop() */
14 #include "dissector_eth.h"
19 extern void ipv6(struct pkt_buff
*pkt
);
20 extern void ipv6_less(struct pkt_buff
*pkt
);
22 void ipv6(struct pkt_buff
*pkt
)
24 uint8_t traffic_class
;
26 char src_ip
[INET6_ADDRSTRLEN
];
27 char dst_ip
[INET6_ADDRSTRLEN
];
28 struct ipv6hdr
*ip
= (struct ipv6hdr
*) pkt_pull(pkt
, sizeof(*ip
));
29 struct sockaddr_in6 sas
, sad
;
30 const char *city
, *region
, *country
;
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 memset(&sas
, 0, sizeof(sas
));
54 sas
.sin6_family
= PF_INET6
;
55 memcpy(&sas
.sin6_addr
, &ip
->saddr
, sizeof(ip
->saddr
));
57 memset(&sad
, 0, sizeof(sad
));
58 sad
.sin6_family
= PF_INET6
;
59 memcpy(&sad
.sin6_addr
, &ip
->daddr
, sizeof(ip
->daddr
));
61 if (geoip_working()) {
63 if ((country
= geoip6_country_name(&sas
))) {
64 tprintf("%s", country
);
65 if ((region
= geoip6_region_name(&sas
)))
66 tprintf(" / %s", region
);
67 if ((city
= geoip6_city_name(&sas
)))
68 tprintf(" / %s", city
);
73 if ((country
= geoip6_country_name(&sad
))) {
74 tprintf("%s", country
);
75 if ((region
= geoip6_region_name(&sad
)))
76 tprintf(" / %s", region
);
77 if ((city
= geoip6_city_name(&sad
)))
78 tprintf(" / %s", city
);
85 pkt_set_dissector(pkt
, ð_lay3
, ip
->nexthdr
);
88 void ipv6_less(struct pkt_buff
*pkt
)
90 char src_ip
[INET6_ADDRSTRLEN
];
91 char dst_ip
[INET6_ADDRSTRLEN
];
92 struct ipv6hdr
*ip
= (struct ipv6hdr
*) pkt_pull(pkt
, sizeof(*ip
));
97 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
98 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
100 tprintf(" %s/%s Len %u", src_ip
, dst_ip
,
101 ntohs(ip
->payload_len
));
103 pkt_set_dissector(pkt
, ð_lay3
, ip
->nexthdr
);
106 struct protocol ipv6_ops
= {
109 .print_less
= ipv6_less
,