Tor  0.4.7.0-alpha-dev
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-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"
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];
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) */
Country type for geoip.
int16_t country_t
Definition: country.h:17
int geoip_get_country_by_addr(const tor_addr_t *addr)
Definition: geoip.c:424
STATIC int geoip_parse_entry(const char *line, sa_family_t family)
Definition: geoip.c:163
STATIC void clear_geoip_db(void)
Definition: geoip.c:484
int geoip_get_country_by_ipv6(const struct in6_addr *addr)
Definition: geoip.c:407
int geoip_load_file(sa_family_t family, const char *filename, int severity)
Definition: geoip.c:324
const struct smartlist_t * geoip_get_countries(void)
Definition: geoip.c:89
const char * geoip_db_digest(sa_family_t family)
Definition: geoip.c:473
int geoip_is_loaded(sa_family_t family)
Definition: geoip.c:458
country_t geoip_get_country(const char *countrycode)
Definition: geoip.c:101
void geoip_free_all(void)
Definition: geoip.c:510
const char * geoip_get_country_name(country_t num)
Definition: geoip.c:447
int geoip_get_country_by_ipv4(uint32_t ipaddr)
Definition: geoip.c:391
int geoip_get_n_countries(void)
Definition: geoip.c:437
Define in6_addr, its members, and related types on platforms that lack it.
uint16_t sa_family_t
Definition: inaddr_st.h:77
Declarations for types used throughout the Tor networking system.
char countrycode[3]
Definition: geoip.h:35
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127