]> jfr.im git - irc/quakenet/newserv.git/blobdiff - geoip/geoip.c
fix indentation
[irc/quakenet/newserv.git] / geoip / geoip.c
index 47f3024594dc2eff21b298c3e63d11c60c2b9330..0201f6be4dfaacd9ce16602b26dd922d652e1711 100644 (file)
@@ -8,9 +8,17 @@
 #include "../core/config.h"
 #include "../core/hooks.h"
 #include "../control/control.h"
+#include "../lib/version.h"
 
+#include <strings.h>
+
+#include "libGeoIP.h"
 #include "geoip.h"
 
+#warning This module is GPLed. Load/link at your peril.
+
+MODULE_VERSION("");
+
 int geoip_totals[COUNTRY_MAX + 1];
 int geoip_nickext = -1;
 GeoIP *gi = NULL;
@@ -63,7 +71,11 @@ void _fini(void) {
 }
 
 void geoip_setupuser(nick *np) {
-  int country = GeoIP_id_by_ipnum(gi, np->ipaddress);
+  if (!irc_in_addr_is_ipv4(&np->p_ipaddr)) 
+    return; /* geoip only supports ipv4 */
+
+  unsigned int ip = irc_in_addr_v4_to_int(&np->p_ipaddr);
+  int country = GeoIP_id_by_ipnum(gi, ip);
   if((country < COUNTRY_MIN) || (country > COUNTRY_MAX))
     return;
 
@@ -105,3 +117,11 @@ void geoip_whois_handler(int hooknum, void *arg) {
   }
 }
 
+int geoip_lookupcode(char *code) {
+  int i;
+  for(i=COUNTRY_MIN;i<COUNTRY_MAX;i++)
+    if(!strcasecmp(code, GeoIP_country_code[i]))
+      return i;
+
+  return -1;
+}