auto
      gˆÓ�þZlq¬Ü¢Z„#„óì„¯2ßëçÂé ?÷     g/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/* GeoIP.h
 *
 * Copyright (C) 2016 MaxMind, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 */

#ifndef GEOIP_H
#define GEOIP_H

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#if !defined(_WIN32)
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#else /* !defined(_WIN32) */
#include <winsock2.h>
#include <ws2tcpip.h>
#define FILETIME_TO_USEC(ft)                                                   \
    (((unsigned __int64)ft.dwHighDateTime << 32 | ft.dwLowDateTime) / 10)
#endif /* !defined(_WIN32) */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>  /* for fstat */
#include <sys/types.h> /* for fstat */

#define SEGMENT_RECORD_LENGTH 3
#define LARGE_SEGMENT_RECORD_LENGTH 4
#define STANDARD_RECORD_LENGTH 3
#define ORG_RECORD_LENGTH 4
#define MAX_RECORD_LENGTH 4
#define NUM_DB_TYPES (38 + 1)

/* 128 bit address in network order */
typedef struct in6_addr geoipv6_t;

#define GEOIP_CHKBIT_V6(bit, ptr)                                              \
    (ptr[((127UL - bit) >> 3)] & (1UL << (~(127 - bit) & 7)))

typedef struct GeoIPTag {
    FILE *GeoIPDatabase;
    char *file_path;
    unsigned char *cache;
    unsigned char *index_cache;
    unsigned int *databaseSegments;
    char databaseType;
    time_t mtime;
    int flags;
    off_t size;
    char record_length;
    int charset;     /* 0 iso-8859-1 1 utf8 */
    int record_iter; /* used in GeoIP_next_record */
    int netmask;     /* netmask of last lookup - set using depth in
                        _GeoIP_seek_record */
    time_t last_mtime_check;
    off_t dyn_seg_size; /* currently only used by the cityconfidence database */
    unsigned int ext_flags; /* bit 0 teredo support enabled */
} GeoIP;

typedef struct GeoIPLookup { int netmask; } GeoIPLookup;

typedef enum { GEOIP_TEREDO_BIT = 0 } GeoIPExtFlags;

typedef enum {
    GEOIP_CHARSET_ISO_8859_1 = 0,
    GEOIP_CHARSET_UTF8 = 1
} GeoIPCharset;

typedef struct GeoIPRegionTag {
    char country_code[3];
    char region[3];
} GeoIPRegion;

typedef enum {
    GEOIP_STANDARD = 0,
    GEOIP_MEMORY_CACHE = 1,
    GEOIP_CHECK_CACHE = 2,
    GEOIP_INDEX_CACHE = 4,
    GEOIP_MMAP_CACHE = 8,
    GEOIP_SILENCE = 16,
} GeoIPOptions;

typedef enum {
    GEOIP_COUNTRY_EDITION = 1,
    GEOIP_REGION_EDITION_REV0 = 7,
    GEOIP_CITY_EDITION_REV0 = 6,
    GEOIP_ORG_EDITION = 5,
    GEOIP_ISP_EDITION = 4,
    GEOIP_CITY_EDITION_REV1 = 2,
    GEOIP_REGION_EDITION_REV1 = 3,
    GEOIP_PROXY_EDITION = 8,
    GEOIP_ASNUM_EDITION = 9,
    GEOIP_NETSPEED_EDITION = 10,
    GEOIP_DOMAIN_EDITION = 11,
    GEOIP_COUNTRY_EDITION_V6 = 12,
    GEOIP_LOCATIONA_EDITION = 13,
    GEOIP_ACCURACYRADIUS_EDITION = 14,
    GEOIP_CITYCONFIDENCE_EDITION = 15,     /* unsupported */
    GEOIP_CITYCONFIDENCEDIST_EDITION = 16, /* unsupported */
    GEOIP_LARGE_COUNTRY_EDITION = 17,
    GEOIP_LARGE_COUNTRY_EDITION_V6 = 18,
    GEOIP_CITYCONFIDENCEDIST_ISP_ORG_EDITION =
        19,                         /* unused, but gaps are not allowed */
    GEOIP_CCM_COUNTRY_EDITION = 20, /* unused, but gaps are not allowed */
    GEOIP_ASNUM_EDITION_V6 = 21,
    GEOIP_ISP_EDITION_V6 = 22,
    GEOIP_ORG_EDITION_V6 = 23,
    GEOIP_DOMAIN_EDITION_V6 = 24,
    GEOIP_LOCATIONA_EDITION_V6 = 2