Tor  0.4.5.0-alpha-dev
Data Structures | Functions
geoip.h File Reference

Header file for geoip.c. More...

#include "orconfig.h"
#include "lib/net/nettypes.h"
#include "lib/testsupport/testsupport.h"
#include "lib/net/inaddr_st.h"
#include "lib/geoip/country.h"

Go to the source code of this file.

Data Structures

struct  geoip_country_t
 

Functions

int geoip_get_country_by_ipv4 (uint32_t ipaddr)
 
int geoip_get_country_by_ipv6 (const struct in6_addr *addr)
 
const struct smartlist_tgeoip_get_countries (void)
 
int geoip_load_file (sa_family_t family, const char *filename, int severity)
 
int geoip_get_country_by_addr (const struct tor_addr_t *addr)
 
int geoip_get_n_countries (void)
 
const char * geoip_get_country_name (country_t num)
 
int geoip_is_loaded (sa_family_t family)
 
const char * geoip_db_digest (sa_family_t family)
 
country_t geoip_get_country (const char *countrycode)
 
void geoip_free_all (void)
 

Detailed Description

Header file for geoip.c.

Definition in file geoip.h.

Function Documentation

◆ geoip_db_digest()

const char* geoip_db_digest ( sa_family_t  family)

Return the hex-encoded SHA1 digest of the loaded GeoIP file. The result does not need to be deallocated, but will be overwritten by the next call of hex_str().

Definition at line 473 of file geoip.c.

◆ geoip_free_all()

void geoip_free_all ( void  )

Release all storage held in this file.

Definition at line 510 of file geoip.c.

◆ geoip_get_countries()

const struct smartlist_t* geoip_get_countries ( void  )

Return a list of geoip_country_t for all known countries.

Definition at line 89 of file geoip.c.

Referenced by geoip_get_request_history().

◆ geoip_get_country()

country_t geoip_get_country ( const char *  country)

Return the index of the country's entry in the GeoIP country list if it is a valid 2-letter country code, otherwise return -1.

Definition at line 101 of file geoip.c.

◆ geoip_get_country_by_ipv4()

int geoip_get_country_by_ipv4 ( uint32_t  ipaddr)

Given an IP address in host order, return a number representing the country to which that address belongs, -1 for "No geoip information available", or 0 for the 'unknown country'. The return value will always be less than geoip_get_n_countries(). To decode it, call geoip_get_country_name().

Definition at line 391 of file geoip.c.

Referenced by geoip_get_country_by_addr(), and getinfo_helper_geoip().

◆ geoip_get_country_by_ipv6()

int geoip_get_country_by_ipv6 ( const struct in6_addr addr)

Given an IPv6 address, return a number representing the country to which that address belongs, -1 for "No geoip information available", or 0 for the 'unknown country'. The return value will always be less than geoip_get_n_countries(). To decode it, call geoip_get_country_name().

Definition at line 407 of file geoip.c.

Referenced by geoip_get_country_by_addr(), and getinfo_helper_geoip().

◆ geoip_get_country_name()

const char* geoip_get_country_name ( country_t  num)

Return the two-letter country code associated with the number num, or "??" for an unknown value.

Definition at line 447 of file geoip.c.

Referenced by addr_is_in_cc_list().

◆ geoip_get_n_countries()

int geoip_get_n_countries ( void  )

Return the number of countries recognized by the GeoIP country list.

Definition at line 437 of file geoip.c.

Referenced by geoip_get_client_history().

◆ geoip_is_loaded()

int geoip_is_loaded ( sa_family_t  family)

Return true iff we have loaded a GeoIP database.

Definition at line 458 of file geoip.c.

Referenced by config_maybe_load_geoip_files_(), geoip_get_client_history(), and getinfo_helper_geoip().

◆ geoip_load_file()

int geoip_load_file ( sa_family_t  family,
const char *  filename,
int  severity 
)

Clear appropriate GeoIP database, based on family, and reload it from the file filename. Return 0 on success, -1 on failure.

Recognized line formats for IPv4 are: INTIPLOW,INTIPHIGH,CC and "INTIPLOW","INTIPHIGH","CC","CC3","COUNTRY NAME" where INTIPLOW and INTIPHIGH are IPv4 addresses encoded as 4-byte unsigned integers, and CC is a country code.

Recognized line format for IPv6 is: IPV6LOW,IPV6HIGH,CC where IPV6LOW and IPV6HIGH are IPv6 addresses and CC is a country code.

It also recognizes, and skips over, blank lines and lines that start with '#' (comments).

Definition at line 324 of file geoip.c.

Referenced by config_load_geoip_file_().