Tor 0.4.9.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
22STATIC int geoip_parse_entry(const char *line, sa_family_t family);
23STATIC void clear_geoip_db(void);
24
25STATIC int geoip_get_country_by_ipv4(uint32_t ipaddr);
26STATIC int geoip_get_country_by_ipv6(const struct in6_addr *addr);
27#endif /* defined(GEOIP_PRIVATE) */
28
29struct in6_addr;
30struct tor_addr_t;
31
32/** A per-country GeoIP record. */
33typedef struct geoip_country_t {
34 /** A nul-terminated two-letter country-code. */
35 char countrycode[3];
37
38struct smartlist_t;
39const struct smartlist_t *geoip_get_countries(void);
40
41int geoip_load_file(sa_family_t family, const char *filename, int severity);
42MOCK_DECL(int, geoip_get_country_by_addr, (const struct tor_addr_t *addr));
44const char *geoip_get_country_name(country_t num);
46const char *geoip_db_digest(sa_family_t family);
47MOCK_DECL(country_t, geoip_get_country, (const char *countrycode));
48
49void geoip_free_all(void);
50
51#endif /* !defined(TOR_GEOIP_H) */
Country type for geoip.
int16_t country_t
Definition: country.h:17
STATIC int geoip_get_country_by_ipv6(const struct in6_addr *addr)
Definition: geoip.c:407
int geoip_get_country_by_addr(const tor_addr_t *addr)
Definition: geoip.c:424
STATIC int geoip_get_country_by_ipv4(uint32_t ipaddr)
Definition: geoip.c:391
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_load_file(sa_family_t family, const char *filename, int severity)
Definition: geoip.c:324
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 struct smartlist_t * geoip_get_countries(void)
Definition: geoip.c:89
int geoip_get_n_countries(void)
Definition: geoip.c:437
const char * geoip_get_country_name(country_t num)
Definition: geoip.c:447
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