1 /* Copyright (c) 2001 Matej Pfajfar. 2 * Copyright (c) 2001-2004, Roger Dingledine. 3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. 4 * Copyright (c) 2007-2021, The Tor Project, Inc. */ 5 /* See LICENSE for licensing information */ 6 7 /** 8 * \file geoip.h 9 * \brief Header file for geoip.c. 10 **/ 11 12 #ifndef TOR_GEOIP_H 13 #define TOR_GEOIP_H 14 15 #include "orconfig.h" 16 #include "lib/net/nettypes.h" 17 #include "lib/testsupport/testsupport.h" 18 #include "lib/net/inaddr_st.h" 19 #include "lib/geoip/country.h" 20 21 #ifdef GEOIP_PRIVATE 22 STATIC int geoip_parse_entry(const char *line, sa_family_t family); 23 STATIC void clear_geoip_db(void); 24 #endif /* defined(GEOIP_PRIVATE) */ 25 26 struct in6_addr; 27 struct tor_addr_t; 28 29 int geoip_get_country_by_ipv4(uint32_t ipaddr); 30 int geoip_get_country_by_ipv6(const struct in6_addr *addr); 31 32 /** A per-country GeoIP record. */ 33 typedef struct geoip_country_t { 34 /** A nul-terminated two-letter country-code. */ 35 char countrycode[3]; 36 } geoip_country_t; 37 38 struct smartlist_t; 39 const struct smartlist_t *geoip_get_countries(void); 40 41 int geoip_load_file(sa_family_t family, const char *filename, int severity); 42 MOCK_DECL(int, geoip_get_country_by_addr, (const struct tor_addr_t *addr)); 43 MOCK_DECL(int, geoip_get_n_countries, (void)); 44 const char *geoip_get_country_name(country_t num); 45 MOCK_DECL(int, geoip_is_loaded, (sa_family_t family)); 46 const char *geoip_db_digest(sa_family_t family); 47 MOCK_DECL(country_t, geoip_get_country, (const char *countrycode)); 48 49 void geoip_free_all(void); 50 51 #endif /* !defined(TOR_GEOIP_H) */ 52