aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnettrace/hostnames.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fnettrace/hostnames.c')
-rw-r--r--src/fnettrace/hostnames.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/fnettrace/hostnames.c b/src/fnettrace/hostnames.c
index 7cb34e2c4..14ebc4ca0 100644
--- a/src/fnettrace/hostnames.c
+++ b/src/fnettrace/hostnames.c
@@ -40,30 +40,32 @@ char *retrieve_hostname(uint32_t ip) {
40 errExit("asprintf"); 40 errExit("asprintf");
41 41
42 FILE *fp = popen(cmd, "r"); 42 FILE *fp = popen(cmd, "r");
43 if (fp) { 43 if (!fp) {
44 char *ptr; 44 geoip_not_found = 1;
45 if (fgets(buf, MAXBUF, fp)) { 45 goto out;
46 ptr = strchr(buf, '\n'); 46 }
47 if (ptr) 47
48 *ptr = '\0'; 48 char *ptr;
49 if (strncmp(buf, "GeoIP Country Edition:", 22) == 0) { 49 if (fgets(buf, MAXBUF, fp)) {
50 ptr = buf + 22; 50 ptr = strchr(buf, '\n');
51 if (*ptr == ' ' && *(ptr + 3) == ',' && *(ptr + 4) == ' ') { 51 if (ptr)
52 rv = ptr + 5; 52 *ptr = '\0';
53 if (strcmp(rv, "United States") == 0) 53 if (strncmp(buf, "GeoIP Country Edition:", 22) == 0) {
54 rv = "US"; 54 ptr = buf + 22;
55 } 55 if (*ptr == ' ' && *(ptr + 3) == ',' && *(ptr + 4) == ' ') {
56 rv = ptr + 5;
57 if (strcmp(rv, "United States") == 0)
58 rv = "US";
56 } 59 }
57 } 60 }
58 pclose(fp);
59 return strdup(rv);
60 } 61 }
61 else 62 pclose(fp);
62 geoip_not_found = 1; 63 if (rv)
64 rv = strdup(rv);
63 65
66out:
64 free(cmd); 67 free(cmd);
65 68 return rv;
66 return NULL;
67} 69}
68 70
69void load_hostnames(const char *fname) { 71void load_hostnames(const char *fname) {