本文整理汇总了C++中GeoIP_open函数的典型用法代码示例。如果您正苦于以下问题:C++ GeoIP_open函数的具体用法?C++ GeoIP_open怎么用?C++ GeoIP_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GeoIP_open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: geoip_init
/** 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 */
}
开发者ID:NX-Andro,项目名称:nefarious2,代码行数:36,代码来源:ircd_geoip.c
示例2: set_geoip_info
void
set_geoip_info(struct userNode *user)
{
if(IsLocal(user))
return;
/* Need the libs and the headers if this is going to compile properly */
#if defined(HAVE_LIBGEOIP)&&defined(HAVE_GEOIP_H)&&defined(HAVE_GEOIPCITY_H)
GeoIPRecord * gir;
const char *geoip_data_file = NULL;
const char *geoip_city_file = NULL;
geoip_data_file = conf_get_data("services/opserv/geoip_data_file", RECDB_QSTRING);
geoip_city_file = conf_get_data("services/opserv/geoip_city_data_file", RECDB_QSTRING);
if ((!geoip_data_file && !geoip_city_file))
return; /* Admin doesnt want to use geoip functions */
if (geoip_data_file && !gi)
gi = GeoIP_open(geoip_data_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE);
if (geoip_city_file && !cgi)
cgi = GeoIP_open(geoip_city_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE);
if (cgi) {
gir = GeoIP_record_by_name(cgi, user->hostname);
if (gir) {
user->country_name = strdup(gir->country_name ? gir->country_name : "");
user->country_code = strdup(gir->country_code ? gir->country_code : "");
user->city = strdup(gir->city ? gir->city : "");
user->region = strdup(gir->region ? gir->region : "");
user->postal_code = strdup(gir->postal_code ? gir->postal_code : "");
user->latitude = gir->latitude ? gir->latitude : 0;
user->longitude = gir->longitude ? gir->longitude : 0;
user->dma_code = gir->dma_code ? gir->dma_code : 0;
user->area_code = gir->area_code ? gir->area_code : 0;
GeoIPRecord_delete(gir);
}
return;
} else if (gi) {
const char *country = GeoIP_country_name_by_name(gi, user->hostname);
user->country_name = strdup(country ? country : "");
return;
}
return;
#endif
}
开发者ID:NX-Andro,项目名称:x3,代码行数:50,代码来源:hash.c
示例3: init_function
int
init_function(struct vmod_priv *pp, const struct VCL_conf *conf)
{
pp->priv = malloc(sizeof(struct GeoIP_databases));
if (!pp->priv)
return 1;
struct GeoIP_databases* db = (struct GeoIP_databases*)pp->priv;
db->country = GeoIP_new(GEOIP_MMAP_CACHE);
db->org = GeoIP_open(GeoIPDBFileName[GEOIP_ORG_EDITION], GEOIP_MMAP_CACHE);
db->region = GeoIP_open(GeoIPDBFileName[GEOIP_REGION_EDITION_REV1], GEOIP_MMAP_CACHE);
pp->free = &free_databases;
return (0);
}
开发者ID:flecoz,项目名称:geoip-vmod,代码行数:15,代码来源:vmod_geoip.c
示例4: PyObject_New
static PyObject *GeoIP_open_Py(PyObject * self, PyObject * args)
{
GeoIP_GeoIPObject *GeoIP;
char *filename;
int flags;
if (!PyArg_ParseTuple(args, "si", &filename, &flags)) {
return NULL;
}
GeoIP = PyObject_New(GeoIP_GeoIPObject, &GeoIP_GeoIPType);
if (!GeoIP)
return NULL;
GeoIP->gi = GeoIP_open(filename, flags);
if (!GeoIP->gi) {
PyErr_SetString(PyGeoIPError, "Can't create GeoIP->gi object");
Py_DECREF(GeoIP);
return NULL;
}
return (PyObject *) GeoIP;
}
开发者ID:5n1p,项目名称:geoip-api-python,代码行数:25,代码来源:py_GeoIP.c
示例5: esgf_geolookup
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;
}
开发者ID:ESGF,项目名称:esgf-dashboard,代码行数:34,代码来源:libiplookup.c
示例6: rb_geoip_database_new
/* Generic initializer */
static VALUE rb_geoip_database_new(VALUE mGeoIP_Database_Class, int argc, VALUE *argv, VALUE self)
{
GeoIP *gi;
VALUE database = Qnil;
VALUE filename, load_option = Qnil, check_cache = Qnil;
int flag;
rb_scan_args(argc, argv, "12", &filename, &load_option, &check_cache);
if(NIL_P(load_option))
load_option = rb_geoip_memory;
if(NIL_P(check_cache))
check_cache = Qfalse;
Check_Type(load_option, T_SYMBOL);
if(flag = check_load_option(load_option)) flag;
if(RTEST(check_cache)) flag |= GEOIP_CHECK_CACHE;
if(gi = GeoIP_open(StringValuePtr(filename), flag)) {
database = Data_Wrap_Struct(mGeoIP_Database_Class, 0, GeoIP_delete, gi);
rb_obj_call_init(database, 0, 0);
} else {
rb_sys_fail("Problem opening database");
}
return database;
}
开发者ID:GaaraLi,项目名称:geoip,代码行数:27,代码来源:geoip.c
示例7: main
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;
}
开发者ID:Anshumakkar,项目名称:resiprocate,代码行数:35,代码来源:test-geoip-isp.c
示例8: loadGeoIP
static void loadGeoIP(void) {
int i;
struct stat statbuf;
/* Initialize GeoIP databases */
for(i=0; myGlobals.configFileDirs[i] != NULL; i++) {
char path[256];
safe_snprintf(__FILE__, __LINE__, path, sizeof(path),
"%s%c%s",
myGlobals.configFileDirs[i],
CONST_PATH_SEP, GEO_IP_FILE);
revertSlashIfWIN32(path, 0);
if(stat(path, &statbuf) == 0) {
if((myGlobals.geo_ip_db = GeoIP_open(path, GEOIP_CHECK_CACHE)) != NULL) {
traceEvent(CONST_TRACE_INFO, "GeoIP: loaded config file %s", path);
break;
}
}
}
if(myGlobals.geo_ip_db == NULL)
traceEvent(CONST_TRACE_ERROR, "GeoIP: unable to load file %s", GEO_IP_FILE);
/* *************************** */
for(i=0; myGlobals.configFileDirs[i] != NULL; i++) {
char path[256];
safe_snprintf(__FILE__, __LINE__, path, sizeof(path),
"%s%c%s",
myGlobals.configFileDirs[i],
CONST_PATH_SEP, GEO_IP_ASN_FILE);
revertSlashIfWIN32(path, 0);
if(stat(path, &statbuf) == 0) {
if((myGlobals.geo_ip_asn_db = GeoIP_open(path, GEOIP_CHECK_CACHE)) != NULL) {
traceEvent(CONST_TRACE_INFO, "GeoIP: loaded ASN config file %s", path);
break;
}
}
}
if(myGlobals.geo_ip_asn_db == NULL)
traceEvent(CONST_TRACE_ERROR, "GeoIP: unable to load ASN file %s", GEO_IP_ASN_FILE);
}
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:47,代码来源:globals-core.c
示例9: ngx_stream_geoip_org
static char *
ngx_stream_geoip_org(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_stream_geoip_conf_t *gcf = conf;
ngx_str_t *value;
if (gcf->org) {
return "is duplicate";
}
value = cf->args->elts;
gcf->org = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
if (gcf->org == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"GeoIP_open(\"%V\") failed", &value[1]);
return NGX_CONF_ERROR;
}
if (cf->args->nelts == 3) {
if (ngx_strcmp(value[2].data, "utf8") == 0) {
GeoIP_set_charset(gcf->org, GEOIP_CHARSET_UTF8);
} else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid parameter \"%V\"", &value[2]);
return NGX_CONF_ERROR;
}
}
switch (gcf->org->databaseType) {
case GEOIP_ISP_EDITION:
case GEOIP_ORG_EDITION:
case GEOIP_DOMAIN_EDITION:
case GEOIP_ASNUM_EDITION:
return NGX_CONF_OK;
#if (NGX_HAVE_GEOIP_V6)
case GEOIP_ISP_EDITION_V6:
case GEOIP_ORG_EDITION_V6:
case GEOIP_DOMAIN_EDITION_V6:
case GEOIP_ASNUM_EDITION_V6:
gcf->org_v6 = 1;
return NGX_CONF_OK;
#endif
default:
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid GeoIP database \"%V\" type:%d",
&value[1], gcf->org->databaseType);
return NGX_CONF_ERROR;
}
}
开发者ID:SeTriones,项目名称:nginx,代码行数:59,代码来源:ngx_stream_geoip_module.c
示例10: geoip_database_file_dir_param1
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);
}
开发者ID:loveshell,项目名称:ironbee,代码行数:58,代码来源:geoip.c
示例11: main
int main(int argc, char **argv) {
const char *geoipfilename = DEFAULT_GEOIPFILE;
GeoIP *gip = NULL;
GeoIPRecord *gir = NULL;
char *name;
const char *region_name;
int edition, i;
if ((argc != 2) && (argc != 4)) {
printf("Usage: geoiplookup_city [-f custom_file] <hostname_or_ip>\n");
return 1;
}
i = 1;
while (i < argc) {
if (strcmp(argv[i],"-f") == 0) {
if ((i+1) < argc){
i++;
geoipfilename = argv[i];
}
} else {
name = argv[i];
}
i++;
}
gip = GeoIP_open(geoipfilename, GEOIP_STANDARD);
edition = GeoIP_database_edition(gip);
if (edition == GEOIP_COUNTRY_EDITION) {
short int country_id = GeoIP_country_id_by_name(gip, name);
region_name = GeoIP_country_continent[country_id];
printf("%s\n", region_name);
} else if ((edition == GEOIP_CITY_EDITION_REV0) ||
(edition == GEOIP_CITY_EDITION_REV1)) {
gir = GeoIP_record_by_name(gip, name);
if (NULL == gir) {
printf("%s: IP Address not found\n", GeoIPDBDescription[edition]);
return 1;
} else {
printf("Continent: %s\n"
"Country: %s\n"
"Region id: %s\n"
"Region: %s\n"
"City: %s\n"
"Latitude: %f\n"
"Longitude: %f\n", gir->continent_code,
gir->country_code,
gir->region,
GeoIP_region_name_by_code(gir->country_code, gir->region),
gir->city,
gir->latitude,
gir->longitude);
}
}
return 0;
}
开发者ID:hayalci,项目名称:mirrorbrain,代码行数:58,代码来源:geoiplookup_city.c
示例12: GeoIP_open
/* 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");
}
开发者ID:ospatrol,项目名称:ospatrol,代码行数:47,代码来源:log.c
示例13: GeoIP_open
/** Возвращает объект GeoIP для определения города по ip.
При первом вызове пытается открыть файл с базой данных, указанный в
параметре ``filename``. Если ``filename`` не задан
*/
GeoIP *GeoCity(const char *filename)
{
static GeoIP *geo = 0;
static bool open_failed = false;
if (open_failed)
return 0;
if (geo)
return geo;
if (filename)
geo = GeoIP_open(filename, GEOIP_MEMORY_CACHE);
else
geo = GeoIP_open("/usr/share/GeoIP/GeoLiteCity.dat",
GEOIP_MEMORY_CACHE);
open_failed = geo? false : true;
return geo;
}
开发者ID:alex43dm,项目名称:ad,代码行数:23,代码来源:GeoIPTools.cpp
示例14: _tag_attr
static int _tag_attr(char *tagname, char *attrname, char *attrvalue, XML_CONFIG *config) {
struct rdb_options_s *options = ((RDB *) config->backptr)->options;
if (strcasecmp(config->xpath, "/nnodes/options/listen") == 0) {
if (strcasecmp(attrname, "port") == 0 && attrvalue) {
curr_port = atoi(attrvalue);
}
else if (strcasecmp(attrname, "addr") == 0 && attrvalue) {
curr_addr = strdup(attrvalue);
}
} else if (strcasecmp(config->xpath, "/nnodes/options/user") == 0) {
if (strcasecmp(attrname, "uid") == 0 && attrvalue) {
options->uid = atoi(attrvalue);
} else if (strcasecmp(attrname, "gid") == 0 && attrvalue) {
options->gid = atoi(attrvalue);
}
} else if (strcasecmp(config->xpath, "/nnodes/options/pid") == 0) {
if (strcasecmp(attrname, "file") == 0 && attrvalue) {
options->pid = strdup(attrvalue);
}
} else if (strcasecmp(config->xpath, "/nnodes/options/threads") == 0) {
if (strcasecmp(attrname, "value") == 0 && attrvalue) {
options->nthreads = atoi(attrvalue);
}
} else if (strcasecmp(config->xpath, "/nnodes/options/log") == 0) {
if (strcasecmp(attrname, "file") == 0 && attrvalue) {
options->log_file = strdup(attrvalue);
}
else if (strcasecmp(attrname, "level") == 0 && attrvalue) {
options->log_level = atoi(attrvalue);
}
else if (strcasecmp(attrname, "maxfile") == 0 && attrvalue) {
options->log_maxfile = atoi(attrvalue);
}
} else if (strcasecmp(config->xpath, "/nnodes/options/websrv") == 0) {
if (strcasecmp(attrname, "xslt") == 0 && attrvalue) {
options->websrv_xslt = strdup(attrvalue);
}
else if (strcasecmp(attrname, "port") == 0 && attrvalue) {
options->websrv_port = atoi(attrvalue);
}
} else if (strcasecmp(config->xpath, "/nnodes/options/geoip") == 0) {
#ifdef HAVE_GEOIP
if (strcasecmp(attrname, "database") == 0 && attrvalue) {
if ((options->gi = GeoIP_open(attrvalue, GEOIP_MEMORY_CACHE)) == NULL) {
LOG_ERR("error opening database %s", attrvalue);
return -1;
}
}
#else
LOG_WARN ("%s\n", "not compiled with geoip");
#endif
}
return 0;
}
开发者ID:safchain,项目名称:nnodes,代码行数:57,代码来源:options.c
示例15: MALLOCORDIE
db_t *ipdata_dbinit()
{
db_t *dbp = MALLOCORDIE(sizeof(db_t), "ipdata_dbinit()");
if(opts.flags & NOAS) /* AS db not requested. */
dbp->asgp = NULL;
else /* AS db requested. */
{
if(!opts.asdb) /* No db name specified. */
{
if(opts.family == AF_INET6) opts.asdb = ASDB_V6_DEFAULT;
else opts.asdb = ASDB_V4_DEFAULT;
}
dbp->asgp = GeoIP_open(opts.asdb, GEOIP_INDEX_CACHE);
if(!dbp->asgp)
{
fputs("ASNum DB requested but not found! "
"Proceeding without it.\n", stderr);
opts.flags |= NOAS;
}
}
if(opts.flags & NOCITY) /* City db not requested. */
dbp->citygp = NULL;
else /* City db requested. */
{
if(!opts.citydb) /* No db name specified. */
{
if(opts.family == AF_INET6) opts.citydb = CITYDB_V6_DEFAULT;
else opts.citydb = CITYDB_V4_DEFAULT;
}
dbp->citygp = GeoIP_open(opts.citydb, GEOIP_INDEX_CACHE);
if(!dbp->citygp)
{
fputs("City DB requested but not found! "
"Proceeding without it.\n", stderr);
opts.flags |= NOCITY;
}
}
return dbp;
}
开发者ID:protoben,项目名称:geotrace,代码行数:44,代码来源:ipdata.c
示例16: LoadDatabase
wxString LoadDatabase(const wxString& path, GeoIPDBTypes type, GeoIPOptions options)
{
if (::wxFileExists(path) && (g_geoIP = GeoIP_open(U2C(path), options)))
{
CSL_LOG_DEBUG("loaded GeoIP database: %s\n", U2C(path));
g_geoIP->charset = GEOIP_CHARSET_UTF8;
}
return g_geoIP ? path : wxT("");
}
开发者ID:aurhat,项目名称:cubelister,代码行数:10,代码来源:CslGeoIP.cpp
示例17: geoip_open_db
/* Geolocation data */
GeoIP *
geoip_open_db (const char *db)
{
GeoIP *geoip;
geoip = GeoIP_open (db, GEOIP_INDEX_CACHE);
if (geoip == NULL)
FATAL ("Unable to open GeoIP City database: %s\n", db);
LOG_DEBUG (("Opened GeoIP City database: %s\n", db));
return geoip;
}
开发者ID:Chilledheart,项目名称:goaccess,代码行数:12,代码来源:geolocation.c
示例18: geoip_init_pv
int geoip_init_pv(char *path)
{
_handle_GeoIP = GeoIP_open(path, GEOIP_MMAP_CACHE);
if(_handle_GeoIP==NULL)
{
LM_ERR("cannot open GeoIP database file at: %s\n", path);
return -1;
}
return 0;
}
开发者ID:GreenfieldTech,项目名称:kamailio,代码行数:11,代码来源:geoip_pv.c
示例19: GeoIP_open_type
static GeoIP *NET_GeoIP_LoadData (int db)
{
GeoIP *data = GeoIP_open_type (db, GEOIP_MEMORY_CACHE);
if (data == nullptr)
{
if (db == GEOIP_COUNTRY_EDITION)
{
std::string dbPath = FS::Path::Build(FS::GetLibPath(), "GeoIP.dat");
data = GeoIP_open (dbPath.c_str(), GEOIP_MEMORY_CACHE);
}
else if (db == GEOIP_COUNTRY_EDITION_V6)
{
std::string dbPath = FS::Path::Build(FS::GetLibPath(), "GeoIPv6.dat");
data = GeoIP_open (dbPath.c_str(), GEOIP_MEMORY_CACHE);
}
}
return data;
}
开发者ID:BlueMustache,项目名称:Unvanquished,代码行数:20,代码来源:net_ip.cpp
示例20: main
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;
}
开发者ID:3sOx,项目名称:asuswrt-merlin,代码行数:53,代码来源:test-geoip-city.c
注:本文中的GeoIP_open函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论