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() */
16 #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
));
31 struct sockaddr_in6 sas
, sad
;
32 const char *city
, *region
, *country
;
37 traffic_class
= (ip
->priority
<< 4) |
38 ((ip
->flow_lbl
[0] & 0xF0) >> 4);
39 flow_label
= ((ip
->flow_lbl
[0] & 0x0F) << 8) |
40 (ip
->flow_lbl
[1] << 4) | ip
->flow_lbl
[2];
42 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
43 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
46 tprintf("Addr (%s => %s), ", src_ip
, dst_ip
);
47 tprintf("Version (%u), ", ip
->version
);
48 tprintf("TrafficClass (%u), ", traffic_class
);
49 tprintf("FlowLabel (%u), ", flow_label
);
50 tprintf("Len (%u), ", ntohs(ip
->payload_len
));
51 tprintf("NextHdr (%u), ", ip
->nexthdr
);
52 tprintf("HopLimit (%u)", ip
->hop_limit
);
55 memset(&sas
, 0, sizeof(sas
));
56 sas
.sin6_family
= PF_INET6
;
57 memcpy(&sas
.sin6_addr
, &ip
->saddr
, sizeof(ip
->saddr
));
59 memset(&sad
, 0, sizeof(sad
));
60 sad
.sin6_family
= PF_INET6
;
61 memcpy(&sad
.sin6_addr
, &ip
->daddr
, sizeof(ip
->daddr
));
63 if (geoip_working()) {
65 if ((country
= geoip6_country_name(sas
))) {
66 tprintf("%s", country
);
67 if ((region
= geoip6_region_name(sas
)))
68 tprintf(" / %s", region
);
69 if ((city
= geoip6_city_name(sas
)))
70 tprintf(" / %s", city
);
75 if ((country
= geoip6_country_name(sad
))) {
76 tprintf("%s", country
);
77 if ((region
= geoip6_region_name(sad
)))
78 tprintf(" / %s", region
);
79 if ((city
= geoip6_city_name(sad
)))
80 tprintf(" / %s", city
);
87 pkt_set_proto(pkt
, ð_lay3
, ip
->nexthdr
);
90 void ipv6_less(struct pkt_buff
*pkt
)
92 char src_ip
[INET6_ADDRSTRLEN
];
93 char dst_ip
[INET6_ADDRSTRLEN
];
94 struct ipv6hdr
*ip
= (struct ipv6hdr
*) pkt_pull(pkt
, sizeof(*ip
));
99 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
100 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
102 tprintf(" %s/%s Len %u", src_ip
, dst_ip
,
103 ntohs(ip
->payload_len
));
105 pkt_set_proto(pkt
, ð_lay3
, ip
->nexthdr
);
108 struct protocol ipv6_ops
= {
111 .print_less
= ipv6_less
,