geoip_sys/
lib.rs

1#![warn(non_camel_case_types, non_upper_case_globals, unused_qualifications)]
2
3use libc::{c_char, c_float, c_int, c_ulong, c_void};
4
5pub type RawGeoIp = *const c_void;
6pub type In6Addr = [u8; 16];
7
8#[repr(C)]
9#[derive(Clone)]
10pub struct GeoIpLookup {
11    pub netmask: c_int,
12}
13
14impl Default for GeoIpLookup {
15    fn default() -> GeoIpLookup {
16        GeoIpLookup { netmask: 0 }
17    }
18}
19
20impl GeoIpLookup {
21    pub fn new() -> GeoIpLookup {
22        GeoIpLookup::default()
23    }
24}
25
26#[link(name = "GeoIP")]
27extern "C" {
28    pub fn GeoIP_open(dbtype: *const c_char, flags: c_int) -> RawGeoIp;
29    pub fn GeoIP_open_type(db_type: c_int, flags: c_int) -> RawGeoIp;
30    pub fn GeoIP_delete(db: RawGeoIp);
31    pub fn GeoIP_database_info(db: RawGeoIp) -> *mut c_char;
32    pub fn GeoIP_name_by_ipnum_gl(
33        db: RawGeoIp,
34        ipnum: c_ulong,
35        gl: *mut GeoIpLookup,
36    ) -> *const c_char;
37    pub fn GeoIP_name_by_ipnum_v6_gl(
38        db: RawGeoIp,
39        ipnum: In6Addr,
40        gl: *mut GeoIpLookup,
41    ) -> *const c_char;
42    pub fn GeoIP_record_by_ipnum(db: RawGeoIp, ipnum: c_ulong) -> *const GeoIpRecord;
43    pub fn GeoIP_record_by_ipnum_v6(db: RawGeoIp, ipnum: In6Addr) -> *const GeoIpRecord;
44    pub fn GeoIPRecord_delete(gir: *const GeoIpRecord);
45    pub fn GeoIP_set_charset(db: RawGeoIp, charset: c_int) -> c_int;
46    pub fn GeoIP_region_name_by_code(
47        country_code: *const c_char,
48        region_code: *const c_char,
49    ) -> *const c_char;
50    pub fn GeoIP_time_zone_by_country_and_region(
51        country_code: *const c_char,
52        region_code: *const c_char,
53    ) -> *const c_char;
54}
55
56#[repr(C)]
57#[derive(Clone)]
58pub struct GeoIpRecord {
59    pub country_code: *const c_char,
60    pub country_code3: *const c_char,
61    pub country_name: *const c_char,
62    pub region: *const c_char,
63    pub city: *const c_char,
64    pub postal_code: *const c_char,
65    pub latitude: c_float,
66    pub longitude: c_float,
67    pub dma_code: c_int,
68    pub area_code: c_int,
69    pub charset: c_int,
70    pub continent_code: *const c_char,
71    pub netmask: c_int,
72}