00001 /* 00002 * $Id: libipg.h.in,v 1.2 2003/12/30 02:59:18 mike Exp $ 00003 * 00004 * libipg.h - interface 00005 * 00006 * Copyright (c) 2003 - 2004 Mike D. Schiffman <mike@infonexus.com> 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 2. Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the distribution. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00019 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00022 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00023 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00024 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00025 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00026 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00027 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00028 * SUCH DAMAGE. 00029 * 00030 */ 00031 00032 #ifndef __LIBIPG_H 00033 #define __LIBIPG_H 00034 00075 #include <stdio.h> 00076 #include <string.h> 00077 #include <stdlib.h> 00078 #include <ctype.h> 00079 #include <errno.h> 00080 00082 #define LIBIPG_VERSION "1.0" 00083 00085 #define LIBIPG_BIG_ENDIAN 1 00086 00088 #define IPGEO_BUF_SIZE 512 00089 00094 struct ipgeo_context 00095 { 00096 FILE *db; 00097 u_int8_t flags; 00098 u_int8_t dbt; 00099 char cc[3]; 00100 char country[128]; 00101 char region[128]; 00102 char city[256]; 00103 char isp[256]; 00104 double latitude; 00105 double longitude; 00106 #define IPGEO_ERRBUF_SIZE 256 00107 char err_buf[IPGEO_ERRBUF_SIZE]; 00108 }; 00110 typedef struct ipgeo_context ipgeo_t; 00111 00121 ipgeo_t * 00122 ipgeo_init(char *file, u_int8_t flags, char *err_buf); 00123 00128 void 00129 ipgeo_destroy(ipgeo_t *ipg); 00130 00137 u_int32_t 00138 ipgeo_ipa2ipn(char *ip); 00139 00170 int 00171 ipgeo_lookup(u_int32_t ipn, u_int8_t flags, ipgeo_t *ipg); 00172 00179 char * 00180 ipgeo_get_cc(ipgeo_t *ipg); 00181 00188 char * 00189 ipgeo_get_country(ipgeo_t *ipg); 00190 00197 char * 00198 ipgeo_get_region(ipgeo_t *ipg); 00199 00206 char * 00207 ipgeo_get_city(ipgeo_t *ipg); 00208 00215 char * 00216 ipgeo_get_isp(ipgeo_t *ipg); 00217 00224 double 00225 ipgeo_get_lat(ipgeo_t *ipg); 00226 00233 double 00234 ipgeo_get_long(ipgeo_t *ipg); 00235 00243 char * 00244 ipgeo_geterror(ipgeo_t *ipg); 00245 00251 int 00252 ipgeo_getfd(ipgeo_t *ipg); 00253 00259 int 00260 ipgeo_getdbt(ipgeo_t *ipg); 00261 00262 #endif /* __IPGEO_H */ 00263 00264 /* EOF */