1 /* 2 * Project : ipv6calc 3 * File : databases/lib/libipv6calc_db_wrapper_DBIP2.h 4 * Version : $Id: ecd344617f720034a777c6caa28aa5c34173c006 $ 5 * Copyright : 2019-2021 by Peter Bieringer <pb (at) bieringer.de> 6 * 7 * Information: 8 * Header file for libipv6calc_db_wrapper_DBIP2.c 9 */ 10 11 #include "ipv6calctypes.h" 12 13 #ifndef _libipv6calc_db_wrapper_DBIP2_h 14 15 #define _libipv6calc_db_wrapper_DBIP2_h 1 16 17 // database types 18 #define DBIP2_DB_COUNTRY_LITE 1 19 #define DBIP2_DB_CITY_LITE 2 20 #define DBIP2_DB_COUNTRY 3 // commercial 21 #define DBIP2_DB_LOCATION 4 // commercial 22 #define DBIP2_DB_ISP 5 // commercial 23 #define DBIP2_DB_LOCATION_ISP 6 // commercial 24 #define DBIP2_DB_MAX DBIP2_DB_LOCATION_ISP 25 26 #define IPV6CALC_DB_DBIP2_INTERNAL_FREE 0x00000001 27 #define IPV6CALC_DB_DBIP2_INTERNAL_COMM 0x00000002 28 29 /*@unused@*/ static const db_file_desc2 libipv6calc_db_wrapper_DBIP2_db_file_desc[] = { 30 // country (lite) 31 { DBIP2_DB_COUNTRY_LITE 32 , "dbip-country-lite.mmdb" 33 , "IPv4/v6 CountryCode (FREE)" 34 , IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_DBIP | IPV6CALC_DB_IP_TO_GEONAMEID | IPV6CALC_DB_IP_TO_COUNTRY 35 , IPV6CALC_DB_DBIP2_INTERNAL_FREE 36 }, 37 38 // city (lite) 39 { DBIP2_DB_CITY_LITE 40 , "dbip-city-lite.mmdb" 41 , "IPv4/v6 City (FREE)" 42 , IPV6CALC_DB_IP_TO_CITY | IPV6CALC_DB_IP_TO_REGION | IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_DBIP | IPV6CALC_DB_IP_TO_GEONAMEID | IPV6CALC_DB_IP_TO_COUNTRY 43 , IPV6CALC_DB_DBIP2_INTERNAL_FREE 44 }, 45 46 // country 47 { DBIP2_DB_COUNTRY 48 , "dbip-country.mmdb" 49 , "IPv4/v6 CountryCode (COMM)" 50 , IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_DBIP | IPV6CALC_DB_IP_TO_GEONAMEID | IPV6CALC_DB_IP_TO_COUNTRY 51 , IPV6CALC_DB_DBIP2_INTERNAL_COMM 52 }, 53 54 // location 55 { DBIP2_DB_LOCATION 56 , "dbip-location.mmdb" 57 , "IPv4/v6 Location (COMM)" 58 , IPV6CALC_DB_IP_TO_CITY | IPV6CALC_DB_IP_TO_REGION | IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_DBIP | IPV6CALC_DB_IP_TO_COUNTRY | IPV6CALC_DB_IP_TO_GEONAMEID 59 , IPV6CALC_DB_DBIP2_INTERNAL_COMM 60 }, 61 62 // ISP 63 { DBIP2_DB_ISP 64 , "dbip-isp.mmdb" 65 , "IPv4/v6 ISP (COMM)", IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_DBIP | IPV6CALC_DB_IP_TO_AS 66 , IPV6CALC_DB_DBIP2_INTERNAL_COMM 67 }, 68 69 // full 70 { DBIP2_DB_LOCATION_ISP 71 , "dbip-location-isp.mmdb" 72 , "IPv4/v6 Location+ISP (COMM)" 73 , IPV6CALC_DB_IP_TO_CITY | IPV6CALC_DB_IP_TO_REGION | IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_DBIP | IPV6CALC_DB_IP_TO_COUNTRY | IPV6CALC_DB_IP_TO_AS | IPV6CALC_DB_IP_TO_GEONAMEID 74 , IPV6CALC_DB_DBIP2_INTERNAL_COMM 75 }, 76 }; 77 78 79 // features 80 extern uint32_t wrapper_features_DBIP2; 81 82 #endif 83 84 extern int libipv6calc_db_wrapper_DBIP2_wrapper_init(void); 85 extern int libipv6calc_db_wrapper_DBIP2_wrapper_cleanup(void); 86 extern void libipv6calc_db_wrapper_DBIP2_wrapper_info(char* string, const size_t size); 87 extern void libipv6calc_db_wrapper_DBIP2_wrapper_print_db_info(const int level_verbose, const char *prefix_string); 88 extern char *libipv6calc_db_wrapper_DBIP2_wrapper_db_info_used(void); 89 extern int libipv6calc_db_wrapper_DBIP2_has_features(const uint32_t features); 90 91 #ifdef SUPPORT_DBIP2 92 #include "libipv6calc_db_wrapper_MMDB.h" 93 94 extern int libipv6calc_db_wrapper_DBIP2_wrapper_country_code_by_addr(const ipv6calc_ipaddr *ipaddrp, char *country, const size_t country_len); 95 extern uint32_t libipv6calc_db_wrapper_DBIP2_wrapper_asn_by_addr(const ipv6calc_ipaddr *ipaddrp); 96 extern uint32_t libipv6calc_db_wrapper_DBIP2_wrapper_GeonameID_by_addr(const ipv6calc_ipaddr *ipaddrp, int *source_ptr); 97 extern int libipv6calc_db_wrapper_DBIP2_all_by_addr(const ipv6calc_ipaddr *ipaddrp, libipv6calc_db_wrapper_geolocation_record *recordp); 98 99 extern char dbip2_db_dir[PATH_MAX]; 100 extern int dbip2_db_comm_to_free_switch_min_delta_months; 101 extern int dbip2_db_only_type; 102 103 extern int libipv6calc_db_wrapper_DBIP2_db_avail(const unsigned int type); 104 extern int libipv6calc_db_wrapper_DBIP2_open_type(const unsigned int type); 105 106 extern const char *libipv6calc_db_wrapper_DBIP2_dbdescription(const unsigned int type); 107 extern char *libipv6calc_db_wrapper_DBIP2_database_info(const unsigned int type); 108 #endif 109