From f118c0774bddd0e3138213395b6d88acf8e0aa2c Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Fri, 13 Jan 2012 10:40:38 +0100 Subject: [PATCH] ashunt: changed open calls to open_type, fixed charset in geoip, use mmap to open database --- src/ashunt.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/ashunt.c b/src/ashunt.c index fed0eb2e..e8bf411f 100644 --- a/src/ashunt.c +++ b/src/ashunt.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -431,12 +430,9 @@ static int handle_ipv4_icmp(uint8_t *packet, size_t len, int ttl, int id, struct iphdr *iph_inner; struct icmphdr *icmph; char *hbuff; - char city_tmp[128], *ptr; - size_t inl, outl; struct sockaddr_in sa; struct asrecord rec; GeoIPRecord *gir; - iconv_t conv; if (iph->protocol != 1) return PKT_NOT_FOR_US; if (iph->daddr != ((struct sockaddr_in *) own)->sin_addr.s_addr) @@ -450,9 +446,6 @@ static int handle_ipv4_icmp(uint8_t *packet, size_t len, int ttl, int id, sizeof(struct icmphdr)); if (ntohs(iph_inner->id) != id) return PKT_NOT_FOR_US; - conv = iconv_open("UTF-8", "ISO8859-1"); - if (!conv || conv == (iconv_t)(-1)) - panic("Cannot open charet converter!\n"); hbuff = xzmalloc(NI_MAXHOST); memset(&sa, 0, sizeof(sa)); sa.sin_family = PF_INET; @@ -467,15 +460,10 @@ static int handle_ipv4_icmp(uint8_t *packet, size_t len, int ttl, int id, if (!dns_resolv) { if (strlen(rec.country) > 0 && gir) { const char *city = make_n_a(gir->city); - inl = strlen(city); - outl = sizeof(city_tmp); - ptr = city_tmp; - memset(city_tmp, 0, sizeof(city_tmp)); - iconv(conv, (char ** restrict) &city, &inl, &ptr, &outl); printf("%s in AS%s (%s, %s, %s, %f, %f), %s %s (%s), %s", hbuff, rec.number, rec.country, GeoIP_country_name_by_ipnum(gi_country, ntohl(iph->saddr)), - city_tmp, gir->latitude, gir->longitude, + city, gir->latitude, gir->longitude, rec.prefix, rec.registry, rec.since, rec.name); } else if (strlen(rec.country) > 0 && !gir) { printf("%s in AS%s (%s, %s), %s %s (%s), %s", hbuff, @@ -491,16 +479,11 @@ static int handle_ipv4_icmp(uint8_t *packet, size_t len, int ttl, int id, PF_INET); if (strlen(rec.country) > 0 && gir) { const char *city = make_n_a(gir->city); - inl = strlen(city); - outl = sizeof(city_tmp); - ptr = city_tmp; - memset(city_tmp, 0, sizeof(city_tmp)); - iconv(conv, (char ** restrict) &city, &inl, &ptr, &outl); printf("%s (%s) in AS%s (%s, %s, %s, %f, %f), %s %s (%s), %s", (hent ? hent->h_name : hbuff), hbuff, rec.number, rec.country, GeoIP_country_name_by_ipnum(gi_country, ntohl(iph->saddr)), - city_tmp, gir->latitude, gir->longitude, + city, gir->latitude, gir->longitude, rec.prefix, rec.registry, rec.since, rec.name); } else if (strlen(rec.country) > 0 && !gir) { @@ -910,10 +893,12 @@ int main(int argc, char **argv) ret = aslookup_prepare(cfg.whois, cfg.whois_port); if (ret < 0) panic("Cannot resolve whois server!\n"); - gi_country = GeoIP_new(GEOIP_STANDARD); - gi_city = GeoIP_open_type(GEOIP_CITY_EDITION_REV1, GEOIP_STANDARD); + gi_country = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_MMAP_CACHE); + gi_city = GeoIP_open_type(GEOIP_CITY_EDITION_REV1, GEOIP_MMAP_CACHE); if (!gi_country || !gi_city) panic("Cannot open GeoIP database!\n"); + GeoIP_set_charset(gi_country, GEOIP_CHARSET_UTF8); + GeoIP_set_charset(gi_city, GEOIP_CHARSET_UTF8); ret = do_trace(&cfg); GeoIP_delete(gi_city); GeoIP_delete(gi_country); -- 2.11.4.GIT