tor  0.4.0.1-alpha
geoip.h
Go to the documentation of this file.
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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_GEOIP_H
13 #define TOR_GEOIP_H
14 
15 #include "orconfig.h"
16 #include "lib/net/nettypes.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 
33 typedef struct geoip_country_t {
34  char countrycode[3];
36 
37 struct smartlist_t;
38 const struct smartlist_t *geoip_get_countries(void);
39 
40 int geoip_load_file(sa_family_t family, const char *filename, int severity);
41 MOCK_DECL(int, geoip_get_country_by_addr, (const struct tor_addr_t *addr));
42 MOCK_DECL(int, geoip_get_n_countries, (void));
43 const char *geoip_get_country_name(country_t num);
44 MOCK_DECL(int, geoip_is_loaded, (sa_family_t family));
45 const char *geoip_db_digest(sa_family_t family);
46 MOCK_DECL(country_t, geoip_get_country, (const char *countrycode));
47 
48 void geoip_free_all(void);
49 
50 #endif /* !defined(TOR_GEOIP_H) */
uint16_t sa_family_t
Definition: inaddr_st.h:77
int geoip_load_file(sa_family_t family, const char *filename, int severity)
Definition: geoip.c:318
const struct smartlist_t * geoip_get_countries(void)
Definition: geoip.c:83
Define in6_addr, its members, and related types on platforms that lack it.
STATIC void clear_geoip_db(void)
Definition: geoip.c:478
const char * geoip_db_digest(sa_family_t family)
Definition: geoip.c:467
const char * geoip_get_country_name(country_t num)
Definition: geoip.c:441
Declarations for types used throughout the Tor networking system.
struct geoip_country_t geoip_country_t
int geoip_get_country_by_ipv6(const struct in6_addr *addr)
Definition: geoip.c:401
int geoip_get_country_by_ipv4(uint32_t ipaddr)
Definition: geoip.c:385
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
STATIC int geoip_parse_entry(const char *line, sa_family_t family)
Definition: geoip.c:157
void geoip_free_all(void)
Definition: geoip.c:504