/** Initialize GeoIP global states. */ void geoip_init(void) { #ifdef USE_GEOIP if (gi4 != NULL) GeoIP_delete(gi4); if (gi6 != NULL) GeoIP_delete(gi6); gi4 = NULL; gi6 = NULL; #endif /* USE_GEOIP */ if (!feature_bool(FEAT_GEOIP_ENABLE)) return; #ifdef USE_GEOIP /* Load IPv4 GeoIP database */ if (feature_str(FEAT_GEOIP_FILE)) { gi4 = GeoIP_open(feature_str(FEAT_GEOIP_FILE), GEOIP_STANDARD); } /* Try to load GeoIP.dat from lib/ if FEAT_GEOIP_FILE was not loaded. */ if (gi4 == NULL) gi4 = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD); /* Load IPv6 GeoIP database */ if (feature_str(FEAT_GEOIP_IPV6_FILE)) { gi6 = GeoIP_open(feature_str(FEAT_GEOIP_IPV6_FILE), GEOIP_STANDARD); } /* Try to load GeoIPv6.dat from lib/ if FEAT_GEOIP_IPV6_FILE was not loaded. */ if (gi6 == NULL) gi6 = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD); #endif /* USE_GEOIP */ }
VOIDSIG signal_rehash(int signum) { #ifdef POSIX_SIGNALS struct sigaction act; #endif #ifdef SIGHUP if (signum == SIGHUP) { #endif Dadmin *a; int i; alog(LOG_NORMAL, "Received SIGHUP: Saving Databases & Rehash Configuration"); if (initconf(denora->config, 1, mainconf) == -1) { denora->qmsg = calloc(50, 1); if (!denora->qmsg) { denora->qmsg = sstrdup(langstr(ALOG_ERR_REHASH_NO_MEM)); } else { ircsnprintf(denora->qmsg, sizeof(denora->qmsg), "%s", langstr(ALOG_ERR_REHASH)); } denora->quitting = 1; send_event(EVENT_SIGNAL, 2, "SIGHUP", denora->qmsg); } else { /* Remove all config file admins from admin struct before re-reading config file */ for (i = 0; i < 1024; i++) { for (a = adminlists[i]; a; a = a->next) { if (a->configfile) { free_admin(a); } break; } } merge_confs(); } /* Reload GeoIP db files */ if (gi) { GeoIP_delete(gi); } if (gi_v6) { GeoIP_delete(gi_v6); } gi = GeoIP_new(GEOIP_STANDARD); gi_v6 = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD); #ifdef POSIX_SIGNALS act.sa_handler = signal_rehash; act.sa_flags = 0; (void) sigemptyset(&act.sa_mask); (void) sigaddset(&act.sa_mask, SIGHUP); (void) sigaction(SIGHUP, &act, NULL); #else # ifndef _WIN32 (void) signal(SIGHUP, signal_rehash); /* sysV -argv */ # endif #endif #ifdef SIGHUP } #endif }
int esgf_geolookup (char *hostname, struct geo_output_struct *geo_output) { char *db_info; GeoIP *gi; int i, ret_code; char *custom_directory = NULL; char *custom_file = NULL; char geoipdat[1024] = { '\0' }; sprintf (geoipdat, "%s/share/GeoIP/%s", GEOIP_DATA_PATH, GEOIPIDATABASE); pmesg(LOG_DEBUG,__FILE__,__LINE__,"Loading GeoLiteCity from %s...\n",geoipdat); if (gi = GeoIP_open (geoipdat, GEOIP_STANDARD)) { i = GeoIP_database_edition (gi); pmesg(LOG_DEBUG,__FILE__,__LINE__," GeoIP database found [Ok]\n"); if (ret_code = geoiplookup (gi, hostname, i, geo_output)) { GeoIP_delete (gi); return ret_code; } } else { pmesg(LOG_ERROR,__FILE__,__LINE__,"%s not available, skipping.Please check ! [Exit]\n",geoipdat); GeoIP_delete (gi); return (-4); } GeoIP_delete (gi); pmesg(LOG_DEBUG,__FILE__,__LINE__,"Geoiplookup ok [code=%d]\n", ret_code); return 0; }
~ModuleGeoIP() { if (ipv4db) GeoIP_delete(ipv4db); if (ipv6db) GeoIP_delete(ipv6db); }
Geolocation::~Geolocation() { #ifdef HAVE_GEOIP if(geo_ip_asn_db != NULL) GeoIP_delete(geo_ip_asn_db); if(geo_ip_asn_db_v6 != NULL) GeoIP_delete(geo_ip_asn_db_v6); if(geo_ip_city_db != NULL) GeoIP_delete(geo_ip_city_db); if(geo_ip_city_db_v6 != NULL) GeoIP_delete(geo_ip_city_db_v6); #endif }
void ipdata_dbfree(db_t *dbp) { if(!dbp) return; if(dbp->citygp) GeoIP_delete(dbp->citygp); if(dbp->asgp) GeoIP_delete(dbp->asgp); free(dbp); }
IpToGeo::~IpToGeo() { if (m_pLocation) GeoIP_delete(m_pLocation); if (m_pOrg) GeoIP_delete(m_pOrg); if (m_pIsp) GeoIP_delete(m_pIsp); if (m_pNetspeed) GeoIP_delete(m_pNetspeed); }
/** * Manage the GeoIP databases at startup and exit. * * We try to open each database one by one. Failing to open one of them is * not fatal because some of them may just not be installed on the system * (for example the Organization db). In that case, all request for an * organization name will return the unknownCountry code. */ static void free_databases(void* ptr) { struct GeoIP_databases* db = (struct GeoIP_databases*)ptr; if (db->country) GeoIP_delete(db->country); if (db->org) GeoIP_delete(db->org); if (db->region) GeoIP_delete(db->region); free(ptr); }
static void ngx_http_geoip_cleanup(void *data) { ngx_http_geoip_conf_t *gcf = data; if (gcf->country) { GeoIP_delete(gcf->country); } if (gcf->city) { GeoIP_delete(gcf->city); } }
int main(int argc, char *argv[]) { FILE *f; GeoIP *gi; char *org; char host[50]; gi = GeoIP_open("../data/GeoIPISP.dat", GEOIP_STANDARD); if (gi == NULL) { fprintf(stderr, "Error opening database\n"); exit(1); } f = fopen("isp_test.txt", "r"); if (f == NULL) { fprintf(stderr, "Error opening isp_test.txt\n"); exit(1); } while (fscanf(f, "%s", host) != EOF) { org = GeoIP_org_by_name(gi, (const char *)host); if (org != NULL) { printf("%s\t%s\n", host, _mk_NA(org)); free(org); } } fclose(f); GeoIP_delete(gi); return 0; }
void closeAll(char * error){ if(statfp != NULL) fclose(statfp); if(handle != NULL) pcap_close(handle); if(mysql != NULL){ mysql_query(mysql,"COMMIT;"); mysql_close(mysql); } if(geoip != NULL) GeoIP_delete(geoip); if(error != NULL) printf("\n%s",error); if(handle != NULL) pcap_stats(handle,&pcapstat); printf("\n\n(Flow) Packet processed:%u\n",procPackets); printf("Discarded packet by pcap: %u\n",pcapstat.ps_drop); printf("Discarded ipv6 packets:%u\n",discPackets); printf("Total local bytes (discarded): %llu (%.2lf GB)\n",discLocBytes,(double)(discLocBytes)/1000000000); printf("Analysis ended at: %u\n",time(NULL)); fflush(stdout); fflush(stderr); if(error != NULL) exit(1); exit(0); }
ConnectionManager::~ConnectionManager () { GeoIP_delete(_geoIp); if (_rsa != 0) { RSA_free(_rsa); } }
static void GeoIP_GeoIP_dealloc(PyObject* self) { GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self; GeoIP_delete(GeoIP->gi); PyObject_Del(self); }
void CIP2Country::Disable() { if (m_geoip) { GeoIP_delete(m_geoip); m_geoip = NULL; } }
void geoip_done(void) { if (gi) { GeoIP_delete(gi); } g_free(flags); }
void geoip_destroy_pv(void) { if(_handle_GeoIP!=NULL) { GeoIP_delete(_handle_GeoIP); _handle_GeoIP=NULL; } }
void CslGeoIP::Unload() { if (g_geoIP) { GeoIP_delete(g_geoIP); g_geoIP = NULL; } }
static void house_keeping (void) { #ifdef TCB_MEMHASH /* free malloc'd int values on the agent list */ if (conf.list_agents) free_agent_list (); #endif /* REVERSE DNS THREAD */ pthread_mutex_lock (&gdns_thread.mutex); /* kill dns pthread */ active_gdns = 0; free_holder (&holder); gdns_free_queue (); /* free uniqmap */ #if defined(TCB_BTREE) || defined(TCB_MEMHASH) /*for (module = 0; module < TOTAL_MODULES; module++) { */ /*free_db_key (get_storage_metric (module, MTRC_UNIQMAP)); */ /*} */ #endif free_storage (); pthread_mutex_unlock (&gdns_thread.mutex); /* DASHBOARD */ if (dash && !conf.output_html) { free_dashboard (dash); reset_find (); } /* GEOLOCATION */ #ifdef HAVE_LIBGEOIP if (geo_location_data != NULL) GeoIP_delete (geo_location_data); #endif /* LOGGER */ free (logger); /* INVALID REQUESTS */ if (conf.invalid_requests_log) { LOG_DEBUG (("Closing invalid requests log.\n")); invalid_log_close (); } /* CONFIGURATION */ if (conf.debug_log) { LOG_DEBUG (("Bye.\n")); dbg_log_close (); } /* free colors */ free_color_lists (); /* free cmd arguments */ free_cmd_args (); }
static ib_status_t geoip_database_file_dir_param1(ib_cfgparser_t *cp, const char *name, const char *p1, void *cbdata) { IB_FTRACE_INIT(); assert(cp!=NULL); assert(name!=NULL); assert(p1!=NULL); ib_status_t rc; size_t p1_len = strlen(p1); size_t p1_unescaped_len; char *p1_unescaped = malloc(p1_len+1); if ( p1_unescaped == NULL ) { IB_FTRACE_RET_STATUS(IB_EALLOC); } rc = ib_util_unescape_string(p1_unescaped, &p1_unescaped_len, p1, p1_len, IB_UTIL_UNESCAPE_NULTERMINATE | IB_UTIL_UNESCAPE_NONULL); if (rc != IB_OK ) { const char *msg = ( rc == IB_EBADVAL )? "GeoIP Database File \"%s\" contains nulls." : "GeoIP Database File \"%s\" is an invalid string."; ib_log_debug(cp->ib, msg, p1); free(p1_unescaped); IB_FTRACE_RET_STATUS(rc); } if (geoip_db != NULL) { GeoIP_delete(geoip_db); geoip_db = NULL; } IB_FTRACE_MSG("Initializing custom GeoIP database..."); IB_FTRACE_MSG(p1_unescaped); geoip_db = GeoIP_open(p1_unescaped, GEOIP_MMAP_CACHE); free(p1_unescaped); if (geoip_db == NULL) { IB_FTRACE_MSG("Failed to initialize GeoIP database."); IB_FTRACE_RET_STATUS(IB_EUNKNOWN); } IB_FTRACE_RET_STATUS(IB_OK); }
static void geoip_child_init(apr_pool_t * p, server_rec * s) { geoip_server_config_rec *cfg; int i, flags; cfg = (geoip_server_config_rec *) ap_get_module_config(s->module_config, &geoip_module); if (cfg->gips) { if (cfg->GeoIPFilenames != NULL) { for (i = 0; i < cfg->numGeoIPFiles; i++) { flags = (cfg->GeoIPFlags2[i] == GEOIP_UNKNOWN) ? cfg->GeoIPFlags : cfg->GeoIPFlags2[i]; if (flags & (GEOIP_MEMORY_CACHE | GEOIP_MMAP_CACHE)) continue; if (cfg->gips[i]) { GeoIP_delete(cfg->gips[i]); } cfg->gips[i] = GeoIP_open(cfg->GeoIPFilenames[i], flags); if (cfg->gips[i]) { if (cfg->GeoIPEnableUTF8) { GeoIP_set_charset(cfg->gips[i], GEOIP_CHARSET_UTF8); } } else { ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "[mod_geoip]: Error while opening data file %s", cfg->GeoIPFilenames[i]); continue; } } } else { if (cfg->gips[0]) GeoIP_delete(cfg->gips[0]); cfg->gips[0] = GeoIP_new(GEOIP_STANDARD); if (!cfg->gips[0]) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "[mod_geoip]: Error while opening data file"); } cfg->numGeoIPFiles = 1; } } }
/* Use the GeoIP API to locate an IP address */ char *GeoIPLookup(char *ip) { GeoIP *gi; GeoIPRecord *gir; char buffer[OS_SIZE_1024 +1]; unsigned long longip; /* Dumb way to detect an IPv6 address */ if (strchr(ip, ':')) { /* Use the IPv6 DB */ gi = GeoIP_open(Config.geoip_db_path, GEOIP_INDEX_CACHE); if (gi == NULL) { merror(INVALID_GEOIP_DB, ARGV0, Config.geoip6_db_path); return("Unknown"); } gir = GeoIP_record_by_name_v6(gi, (const char *)ip); } else { /* Use the IPv4 DB */ /* If we have a RFC1918 IP, do not perform a DB lookup (performance) */ longip = StrIP2Int(ip); if (longip == 0 ) return("Unknown"); if ((longip & NETMASK_8) == RFC1918_10 || (longip & NETMASK_12) == RFC1918_172 || (longip & NETMASK_16) == RFC1918_192) return(""); gi = GeoIP_open(Config.geoip_db_path, GEOIP_INDEX_CACHE); if (gi == NULL) { merror(INVALID_GEOIP_DB, ARGV0, Config.geoip_db_path); return("Unknown"); } gir = GeoIP_record_by_name(gi, (const char *)ip); } if (gir != NULL) { sprintf(buffer,"%s,%s,%s", _mk_NA(gir->country_code), _mk_NA(GeoIP_region_name_by_code(gir->country_code, gir->region)), _mk_NA(gir->city) ); GeoIP_delete(gi); return(buffer); } GeoIP_delete(gi); return("Unknown"); }
int init_function(struct vmod_priv *priv, const struct VCL_conf *conf) { if (gi) { GeoIP_delete(gi); } gi = GeoIP_new(GEOIP_STANDARD); return (0); }
/* Called when module is unloaded. */ static ib_status_t geoip_fini(ib_engine_t *ib, ib_module_t *m, void *cbdata) { if (geoip_db!=NULL) { GeoIP_delete(geoip_db); } ib_log_debug(ib, "GeoIP module unloaded."); return IB_OK; }
void unload() { for (int i=0; i<NUM_DB_TYPES; i++) { db_last_modified[i] = db_last_checked[i] = 0; if (gi[i] != NULL) { GeoIP_delete(gi[i]); gi[i] = NULL; } } }
/* Called when module is unloaded. */ static ib_status_t geoip_fini(ib_engine_t *ib, ib_module_t *m, void *cbdata) { IB_FTRACE_INIT(); if (geoip_db!=NULL) { GeoIP_delete(geoip_db); } ib_log_debug(ib, "GeoIP module unloaded."); IB_FTRACE_RET_STATUS(IB_OK); }
static void geoip_release (void) { _geoip_refs -= 1; if (_geoip_refs <= 0) { GeoIP_delete (_geoip); _geoip = NULL; } }
void geoip_free(GeoIPContainer *container) { if (container->geoip) { GeoIP_delete(container->geoip); } free(container); return; }
void FiniTLDStatistics( void ) { SaveTLDStats(); DBACloseTable( TLD_TABLE ); if( gi ) { GeoIP_delete( gi ); gi = NULL; } list_destroy_auto( tldstatlist ); }
int main(int argc, char *argv[]) { FILE *f; GeoIP *gi; GeoIPRecord *gir; int generate = 0; char host[50]; const char *time_zone = NULL; char **ret; if (argc == 2) { if (!strcmp(argv[1], "gen")) { generate = 1; } } gi = GeoIP_open("../data/GeoIPCity.dat", GEOIP_INDEX_CACHE); if (gi == NULL) { fprintf(stderr, "Error opening database\n"); exit(1); } f = fopen("city_test.txt", "r"); if (f == NULL) { fprintf(stderr, "Error opening city_test.txt\n"); exit(1); } while (fscanf(f, "%s", host) != EOF) { gir = GeoIP_record_by_name(gi, (const char *)host); if (gir != NULL) { ret = GeoIP_range_by_ip(gi, (const char *)host); time_zone = GeoIP_time_zone_by_country_and_region(gir->country_code, gir->region); printf("%s\t%s\t%s\t%s\t%s\t%s\t%f\t%f\t%d\t%d\t%s\t%s\t%s\n", host, _mk_NA(gir->country_code), _mk_NA(gir->region), _mk_NA(GeoIP_region_name_by_code (gir->country_code, gir->region)), _mk_NA(gir->city), _mk_NA(gir->postal_code), gir->latitude, gir->longitude, gir->metro_code, gir->area_code, _mk_NA(time_zone), ret[0], ret[1]); GeoIP_range_by_ip_delete(ret); GeoIPRecord_delete(gir); } } GeoIP_delete(gi); fclose(f); return 0; }
static ib_status_t geoip_database_file_dir_param1(ib_cfgparser_t *cp, const char *name, const char *p1, void *cbdata) { assert(cp!=NULL); assert(name!=NULL); assert(p1!=NULL); ib_status_t rc; size_t p1_len = strlen(p1); size_t p1_unescaped_len; char *p1_unescaped = malloc(p1_len+1); if ( p1_unescaped == NULL ) { return IB_EALLOC; } rc = ib_util_unescape_string(p1_unescaped, &p1_unescaped_len, p1, p1_len, IB_UTIL_UNESCAPE_NULTERMINATE | IB_UTIL_UNESCAPE_NONULL); if (rc != IB_OK ) { const char *msg = ( rc == IB_EBADVAL )? "GeoIP Database File \"%s\" contains nulls." : "GeoIP Database File \"%s\" is an invalid string."; ib_log_debug(cp->ib, msg, p1); free(p1_unescaped); return rc; } if (geoip_db != NULL) { GeoIP_delete(geoip_db); geoip_db = NULL; } geoip_db = GeoIP_open(p1_unescaped, GEOIP_MMAP_CACHE); free(p1_unescaped); if (geoip_db == NULL) { return IB_EUNKNOWN; } return IB_OK; }