• This repository has been archived on 01/Jun/2022
  • Stars
    star
    371
  • Rank 115,103 (Top 3 %)
  • Language
    C
  • License
    Other
  • Created over 12 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DEPRECATED GeoIP Legacy C API

GeoIP Legacy C Library

End of Life

MaxMind will be retiring the GeoIP Legacy databases at the end of May 2022. Until then, this library will only receive critical security and bug fixes. Support for this library will end completely with the last release of the legacy GeoIP databases.

We recommend that you upgrade to our GeoIP2 databases. You can read these from C using libmaxminddb.

See our blog post for more information.

Description

The GeoIP Legacy C library enables the user to find geographical and network information of an IP address. To use this library, you may user our commercial GeoIP Legacy databases. For more details, see:

https://www.maxmind.com/en/geoip2-services-and-databases

IP Geolocation Usage

IP geolocation is inherently imprecise. Locations are often near the center of the population. Any location provided by a GeoIP database should not be used to identify a particular address or household.

Installation

On Ubuntu Using PPA

MaxMind provides a PPA for recent version of Ubuntu. To add the PPA to your APT sources, run:

$ sudo add-apt-repository ppa:maxmind/ppa

Then install the packages by running:

$ sudo apt update
$ sudo apt install libgeoip1 libgeoip-dev geoip-bin

From Source on Unix/Linux

To install, run:

./configure
make
make check
make install

If you are using a GitHub checkout, please run the bootstrap script first to set up the build environment.

The GeoIP Legacy C library relies on GNU make, not on BSD make

From Source with Visual Studio (nmake)

To make a static GeoIP.lib, edit the top level Makefile.vc to reflect where the GeoIP.dat database file should be placed, as well as the locations of the lib, include, and bin directories for installation.

To build and install, issue the following commands from a developer console:

nmake /f Makefile.vc
nmake /f Makefile.vc test
nmake /f Makefile.vc install

From Source with MinGW

./configure
make
cp data/GeoIP.dat test/
make check

Note that GeoIP.dat file should be placed in the same place as GeoIP-enabled executable modules.

Memory Caching and Other Options

There are five options available:

  • GEOIP_STANDARD - Read database from file system. This uses the least memory.
  • GEOIP_MEMORY_CACHE - Load database into memory. Provides faster performance but uses more memory.
  • GEOIP_CHECK_CACHE - Check for updated database. If database has been updated, reload file handle and/or memory cache.
  • GEOIP_INDEX_CACHE - Cache only the the most frequently accessed index portion of the database, resulting in faster lookups than GEOIP_STANDARD, but less memory usage than GEOIP_MEMORY_CACHE. This is useful for larger databases such as GeoIP Legacy Organization and GeoIP Legacy City. Note: for GeoIP Legacy Country, Region and Netspeed databases, GEOIP_INDEX_CACHE is equivalent to GEOIP_MEMORY_CACHE.
  • GEOIP_MMAP_CACHE - Load database into mmap shared memory. MMAP is not available for 32bit Windows.
  • GEOIP_SILENCE - Disables diagnostic messages to stderr in the library; error conditions are detectable via the return values.

These options can be combined using bit operators. For example you can use both GEOIP_MEMORY_CACHE and GEOIP_CHECK_CACHE by calling:

GeoIP_open("/path/to/GeoIP.dat", GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE);

By default, the city name is returned in the ISO-8859-1 charset. To obtain the city name in UTF-8 instead, run:

GeoIP_set_charset(gi, GEOIP_CHARSET_UTF8);

To get the netmask of the netblock of the last lookup, use GeoIP_last_netmask(gi).

Examples

See the following files for examples of how to use the API:

test/
     test-geoip.c
     test-geoip-region.c
     test-geoip-city.c
     test-geoip-isp.c
     test-geoip-org.c
     test-geoip-netspeed.c

These example programs use our GeoIP Legacy databases.

Troubleshooting

Autotool Issues

In case of trouble building from source with libtool or autotools, update the generated configuration files by running:

./bootstrap

or

autoreconf -vfi

or

aclocal && autoconf && automake --add-missing

Threads

Lookups are thread safe, but libGeoIP does not guard the functions. Do not drop or change the GeoIP database if other threads might be using the database.

The recommended pattern is:

  1. open database with GEOIP_MEMORY_CACHE
  2. create_threads(your_thread_entry_function)
  3. use the database
  4. join_threads
  5. close database

Thread Safety on Windows

The Windows build is not thread-safe in STANDARD mode because the pread is not thread-safe.

Other Build Issues

If you run into trouble building your application with GeoIP Legacy support, try adding -fms-extensions to your CFLAGS. If you use Solaris and the default C compiler, use -features=extensions instead. These options enable unnamed union support to fix problems like: improper member use: dma_code or 'GeoIPRecord' has no member named 'dma_code'.

Note that it is recommended that you use GNU make. Also, if you are using OpenBSD, this library requires OpenBSD 3.1 or greater.

If you get a "cannot load shared object file: No such file or directory" error, add the directory libGeoIP.so was installed to the /etc/ld.so.conf file and run ldconfig.

Solaris

On Solaris, if you get a ld: fatal: relocations remain against allocatable but non-writable sections, try running:

make clean
./configure --disable-shared
make

If you get a ar : command not found error, make sure that ar is in your path. On Solaris, ar is typically found in /usr/ccs/bin

AIX

If you get a passing argument 3 of 'gethostbyname_r' from incompatible pointer type error on AIX, untar a fresh copy of this library and delete the following two lines from ./configure:

#define HAVE_GETHOSTBYNAME_R 1

#define GETHOSTBYNAME_R_RETURNS_INT 1

then save the configure script and build it as usual:

./configure
make
sudo make install

Bug Tracker

Please report all issues with this code using the GitHub issue tracker.

If you are having an issue with a MaxMind database that is not specific to this API, please contact MaxMind support.

Contributing

To contribute, please submit a pull request on GitHub.

More Repositories

1

GeoIP2-php

PHP API for GeoIP2 webservice client and database reader
PHP
2,325
star
2

GeoIP2-python

Python code for GeoIP2 webservice client and database reader
Python
1,107
star
3

libmaxminddb

C library for the MaxMind DB file format
C
913
star
4

GeoIP2-java

Java API for GeoIP2 webservice client and database reader
Java
781
star
5

geoipupdate

GeoIP update client code
Go
723
star
6

MaxMind-DB-Reader-php

PHP Reader for the MaxMind DB Database Format
PHP
639
star
7

geoip-api-php

DEPRECATED GeoIP Legacy PHP API
PHP
523
star
8

GeoIP2-dotnet

MaxMind GeoIP2 .NET API
C#
348
star
9

web-service-common-php

Shared code for the MaxMind Web Service PHP client APIs
PHP
288
star
10

MaxMind-DB

Spec and test data for the MaxMind DB file format
Go
277
star
11

geoipupdate-legacy

GeoIP update client code
C
258
star
12

geoip-api-python

DEPRECATED GeoIP Legacy Python API
C
232
star
13

GeoIP2-node

Node.js API for GeoIP2 webservice client and database reader
TypeScript
223
star
14

geoip2-csv-converter

GeoIP2 CSV Format Converter
Go
202
star
15

MaxMind-DB-Reader-python

Python MaxMind DB reader extension
Python
178
star
16

geoip-api-java

DEPRECATED GeoIP Legacy Java API
Java
176
star
17

mmdbinspect

look up records for one or more IPs/networks in one or more .mmdb databases
Go
130
star
18

mod_maxminddb

MaxMind DB Apache Module
C
126
star
19

MaxMind-DB-Reader-java

Java reader for the MaxMind DB format
Java
114
star
20

mmdbwriter

Go library for writing MaxMind DB (mmdb) files
Go
114
star
21

MaxMind-DB-Reader-dotnet

.NET Reader for the MaxMind DB Database Format
C#
102
star
22

MaxMind-DB-Writer-perl

Create MaxMind DB database files
Perl
75
star
23

GeoIP2-ruby

Ruby API for GeoIP2 webservice client and database reader
Ruby
59
star
24

geoip-api-mod_geoip2

DEPRECATED GeoIP Legacy module for Apache 2
C
50
star
25

minfraud-api-php

PHP API for minFraud Score, Insights, and Factors
PHP
49
star
26

geoip-api-csharp2

DEPRECATED GeoIP Legacy C# API
C#
47
star
27

MaxMind-DB-Reader-ruby

Ruby reader for the MaxMind DB Database Format
Ruby
46
star
28

getting-started-with-mmdb

A quick guide to writing and reading from your own MMDB databases.
Perl
37
star
29

minfraud-api-python

Python API for minFraud Score, Insights, and Factors
Python
27
star
30

mmdb-from-go-blogpost

Enriching MMDB files with your own data using Go.
Go
23
star
31

ccfd-api-php

Deprecated minFraud Legacy PHP API
PHP
23
star
32

minfraud-api-dotnet

.NET API for MaxMind minFraud Score, Insights, and Factors
C#
20
star
33

minfraud-api-java

Java API for minFraud Score, Insights, and Factors
Java
19
star
34

GeoIP2-perl

Perl API for MaxMind's GeoIP2 web services and databases
Perl
18
star
35

mm-geofeed-verifier

Verify the format of a geofeed file, and make some comparisons to data in an MMDB file.
Go
16
star
36

minfraud-api-ruby

Ruby API for minFraud Score, Insights, and Factors
Ruby
14
star
37

minfraud-api-node

Node.js API for MaxMind minFraud Score, Insights, and Factors
TypeScript
14
star
38

mm-network-analyzer

A program to aid in diagnosing networking issues
Go
13
star
39

dev-hire-homework

A homework exercise for engineering applicants
Perl
13
star
40

MaxMind-DB-Reader-perl

Read MaxMind DB files and look up IP addresses
Perl
12
star
41

mmdbverify

Verifier for the MaxMind DB format
Go
10
star
42

geoip-api-perl

DEPRECATED GeoIP Legacy Perl API
Perl
10
star
43

Stepford

A vaguely Rake/Make/Cake-like thing for Perl - create steps and let a runner run them
Perl
9
star
44

ccfd-api-java

Deprecated minFraud Legacy Java API
Java
7
star
45

Locale-Country-Multilingual

mapping ISO codes to localized country names
Perl
6
star
46

Database-Migrator

Mirror of Database-Migrator on urth.org
Perl
5
star
47

Net-Works

Sane APIs for IP addresses and networks
Perl
5
star
48

MaxMind-DB-Reader-XS

Fast XS implementation of MaxMind DB reader
Perl
5
star
49

dev-site

Static site generator for https://dev.maxmind.com.
HTML
4
star
50

xgb2code

A converter for xgboost model dumps to code.
Go
4
star
51

ccfd-api-asp

minFraud ASP API
ASP
3
star
52

webservice-paypal-paymentsadvanced

A simple wrapper around the PayPal Payments Advanced web service
Perl
3
star
53

gatling-gen

C++
2
star
54

geoip-api-mscom

DEPRECATED GeoIP Legacy MS COM API
C
2
star
55

App-CISetup

Command line tools to generate and update Travis and AppVeyor configs for Perl libraries
Perl
2
star
56

api-specs

TypeScript
2
star
57

MaxMind-DB-Common-perl

Code shared by the MaxMind DB reader and writer modules
Perl
2
star
58

WebService-PivotalTracker

Perl library for the Pivotal Tracker REST API
Perl
2
star
59

minfraud-api-perl

Perl API for minFraud Score, Insights, and Factors
Perl
2
star
60

TAP-Formatter-TeamCity

Emit test results as TeamCity build messages
Perl
2
star
61

geolite2-ws-blogpost

Integrating MaxMind's Free and Paid IP Geolocation Web Services (in PHP)
PHP
2
star
62

fuzzing-workshop

Code for Summit Fuzzing Workshop
Go
1
star
63

Dist-Zilla-PluginBundle-MAXMIND

Perl
1
star
64

blog-site

Static site generator for https://blog.maxmind.com.
SCSS
1
star
65

TeamCity-Message

Generate TeamCity build messages
Perl
1
star
66

xgbshap

Calculates feature contributions for XGBoost models
Go
1
star