[ipv6calc] using external GeoIP and IP2Location libraries

Niko Tyni ntyni at iki.fi
Fri Feb 9 21:48:32 CET 2007


On Mon, Feb 05, 2007 at 05:42:18PM +0100, Peter Bieringer wrote:
 
> At 02.02.2007 09:40, Niko Tyni wrote:

> > I still plan to hack the build system so that it could use an external
> > copy of the ip2location and geoip source trees, I just haven't gotten
> > around to doing it yet. With it there would be no need of shipping
> > those in the ipv6calc tarball, which would be a good thing IMO.
> 
> For sure, would be great if you find time to do the work.

OK, here we go. This patch adds the following configure options:

--with-ip2location-headers=DIR
--with-ip2location-lib=DIR
--with-ip2location-static

--with-geoip-headers=DIR
--with-geoip-lib=DIR
--with-geoip-static

Furthermore, it renames (for consistency, YMMV)

--enable-geoip-default-file => --with-geoip-default-file

and removes the now unnecessary

--enable-geoip-system

There's also some documentation, including instructions on building
IP2Location (README.BUILDING-IP2LOCATION), as I run into some problems
with it.

The removal of the libraries is not in the patch, you'll have to remove
databases/IP2Location and databases/GeoIP yourself. I did modify the
LICENSE file to anticipate this, though :)

You might want to consider distributing a modified and bootstrapped
version of the IP2Location library tarball separately on your site to
make it easier for users. However, the license of the bigDigits stuff
included [1,2] may pose a problem - as I read it, there's no permission
to distribute the bigDigits source code at all, and the combination is
also undistributable because it's linking GPL code with GPL-incompatible
code [3].

[1] eg. libIP2Location/bigd.c
[2] http://www.di-mgt.com.au/bigdigitsCopyright.txt
[3] http://www.gnu.org/licenses/gpl-faq.html#WhatDoesCompatMean

Cheers,
-- 
Niko Tyni   ntyni at iki.fi
-------------- next part --------------
--- ipv6calc-0.70cvs+20070208.orig/INSTALLING
+++ ipv6calc-0.70cvs+20070208/INSTALLING
@@ -57,7 +57,8 @@
 Following options are used:
  --bindir=/usr/bin  (@bindir@)
  --mandir=/usr/share/man (@mandir@)
- --enable-ip2location (@ENABLE_SUPPORT_IP2LOCATION@)
+ --enable-ip2location (see below for more information)
+ --enable-geoip (see below for more information)
 
 Execute:
  ./configure --bindir=/usr/bin --mandir=/usr/share/man
@@ -79,6 +80,40 @@
  ./databases/ieee-iab/README
  ./databases/ieee-oui/README
 
+IP2LOCATION LIBRARY
+-------------------
+
+You can use the IP2Location library with ipv6calc. The library is available
+at <http://www.ip2location.com/c.aspx>, and the currently supported version
+is 2.1.1. The support is enabled with the --enable-ip2location configure
+option.
+
+If you have installed the IP2Location library in a non-standard place, you
+may find the --with-ip2location-headers=DIR and --with-ip2location-lib=DIR
+configure options useful. If you have problems finding the library at
+runtime, try linking it statically the --with-ip2location-static configure
+option.
+
+If you have problems building the IP2Location library, see the
+README.BUILDING-IP2LOCATION file in the ipv6calc distribution.
+
+GEOIP LIBRARY
+-------------
+
+You can also use the GeoIP library with ipv6calc. The library is available
+at <http://www.maxmind.com/app/ip-location>, and the currently supported
+version is 1.4.1 (although others may work too). The support is enabled
+with the --enable-geoip configure option.
+
+If you have installed the GeoIP library in a non-standard place, you may
+find the --with-geoip-headers=DIR and --with-geoip-lib=DIR configure
+options useful. If you have problems finding the library at runtime,
+try linking it statically the --with-geoip-static configure option.
+
+You can set the path to a default GeoIP database file by using the
+--with-geoip-default-file configure option. This file is used
+when ipv6calc is invoked with the '-G' (or '--db-geoip-default')
+option.
 
 COMPILE
 -------  
--- ipv6calc-0.70cvs+20070208.orig/configure.in
+++ ipv6calc-0.70cvs+20070208/configure.in
@@ -5,13 +5,6 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT(ipv6calc, 0.70.0cvs, ipv6calc at deepspace6.net, ipv6calc)
 
-dnl Define versions of built-in IP location database APIs
-VERSION_IP2LOCATION=2.1.0
-VERSION_GEOIP=1.4.0
-
-AC_DEFINE(VERSION_IP2LOCATION, "2.1.0", Version of IP2Location API.)
-AC_DEFINE(VERSION_GEOIP, "1.4.0", Version of GeoIP API.)
-
 dnl Define version header
 AC_CONFIG_HEADER(config.h)
 
@@ -49,45 +42,97 @@
 AC_ARG_ENABLE([ip2location], 
 	AS_HELP_STRING([--enable-ip2location],
 	               [Enable IP2Location support (default: disabled)]),
-	[if test "x$enable_ip2location" = "xyes"; then
-		ENABLE_SUPPORT_IP2LOCATION=1
-		AC_DEFINE(SUPPORT_IP2LOCATION, 1, Define if you want IP2Location support.)
-	fi])
-AC_SUBST(ENABLE_SUPPORT_IP2LOCATION)
-AC_SUBST(VERSION_IP2LOCATION)
+	[
+        IP2LOCATION="$enableval"
+        IP2LOCATION_LIB="-lIP2Location"
+    ],
+    [IP2LOCATION="no"])
+
+AC_ARG_WITH([ip2location-headers],
+    AS_HELP_STRING([--with-ip2location-headers=DIR],
+                   [IP2Location include files location]),
+    [IP2LOCATION_INCLUDE="-I$withval"])
+
+AC_ARG_WITH([ip2location-lib],
+    AS_HELP_STRING([--with-ip2location-lib=DIR],
+                   [IP2Location library location]),
+    [IP2LOCATION_LIB="-L$withval $IP2LOCATION_LIB"])
+
+AC_ARG_WITH([ip2location-static],
+    AS_HELP_STRING([--with-ip2location-static],
+                   [Explicitly link IP2Location statically (default=no)]),
+    [if test "$withval" != "no"; then 
+        IP2LOCATION_LIB="-Wl,-Bstatic $IP2LOCATION_LIB -Wl,-Bdynamic"
+     fi])
+
+if test "$IP2LOCATION" = "yes"; then
+    CPPFLAGS="$CPPFLAGS $IP2LOCATION_INCLUDE"
+    LDFLAGS="$LDFLAGS $IP2LOCATION_LIB"
+    AC_CHECK_HEADER(IP2Location.h,,
+        [AC_MSG_ERROR([IP2Location library header files not found])]
+    )
+    AC_CHECK_LIB(IP2Location,IP2Location_open,
+        [
+            AC_DEFINE(SUPPORT_IP2LOCATION, 1, Define if you want IP2Location support.)
+        ],
+        [
+            AC_MSG_ERROR([IP2Location library header files were found but the library was not found])
+        ])
+fi
+
+AC_SUBST(IP2LOCATION_INCLUDE)
+AC_SUBST(IP2LOCATION_LIB)
 
 dnl GeoIP support
 AC_ARG_ENABLE([geoip], 
 	AS_HELP_STRING([--enable-geoip],
 	               [Enable GeoIP support (default: disabled)]),
-	[if test "x$enable_geoip" = "xyes"; then
-		ENABLE_SUPPORT_GEOIP=1
-		AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want GeoIP support.)
-	fi])
-
-AC_ARG_ENABLE([geoip-system],
-       AS_HELP_STRING([--enable-geoip-system],
-               [Use the system GeoIP library instead of the bundled one (default: bundled)]),
-       [if test "x$enable_geoip_system" = "xyes"; then
-               AC_CHECK_HEADER([GeoIP.h], [], AC_MSG_ERROR([System GeoIP library not found]))
-               ENABLE_SYSTEM_GEOIP=1
-               ENABLE_SUPPORT_GEOIP=1
-               AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want to use GeoIP support.)
-               AC_DEFINE(ENABLE_GEOIP_SYSTEM, 1, Define if you want to use GeoIP system library support.)
-       fi])
+    [
+        GEOIP="$enableval"
+        GEOIP_LIB="-lGeoIP"
+    ],
+    [GEOIP="no"])
+
+AC_ARG_WITH([geoip-headers],
+    AS_HELP_STRING([--with-geoip-headers=DIR],
+                   [GeoIP include files location]),
+    [GEOIP_INCLUDE="-I$withval"])
+
+AC_ARG_WITH([geoip-lib],
+    AS_HELP_STRING([--with-geoip-lib=DIR],
+                   [GeoIP library location]),
+    [GEOIP_LIB="-L$withval $GEOIP_LIB"])
+
+
+AC_ARG_WITH([geoip-static],
+    AS_HELP_STRING([--with-geoip-static],
+                   [Explicitly link GeoIP statically (default=no)]),
+    [if test "$withval" != "no"; then 
+        GEOIP_LIB="-Wl,-Bstatic $GEOIP_LIB -Wl,-Bdynamic"
+     fi])
 
-AC_ARG_ENABLE([geoip-default-file],
-       AS_HELP_STRING([--enable-geoip-default-file=file],
+AC_ARG_WITH([geoip-default-file],
+       AS_HELP_STRING([--with-geoip-default-file=file],
                [Use a default GeoIP database file when ipv6calc is invoked with '--db-geoip-default|-G']),
-       [if test "x$enable_geoip_default_file" != xno; then
-               AC_DEFINE_UNQUOTED(GEOIP_DEFAULT_FILE, "$enable_geoip_default_file", Define for a default GeoIP database file.)
-               ENABLE_SUPPORT_GEOIP=1
-               AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want to use GeoIP support.)
-       fi])
-
-AC_SUBST(ENABLE_SUPPORT_GEOIP)
-AC_SUBST(VERSION_GEOIP)
-AC_SUBST(ENABLE_SYSTEM_GEOIP)
+       [AC_DEFINE_UNQUOTED(GEOIP_DEFAULT_FILE, "$withval", Define for a default GeoIP database file.)])
+
+if test "$GEOIP" = "yes"; then
+    CPPFLAGS="$CFLAGS $GEOIP_INCLUDE"
+    LDFLAGS="$LDFLAGS $GEOIP_LIB"
+    AC_CHECK_HEADER(GeoIP.h,,
+        [AC_MSG_ERROR([GeoIP library header files not found])]
+    )
+    AC_CHECK_LIB(GeoIP, GeoIP_open,
+        [
+	        AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want GeoIP support.)
+        ],
+        [
+            AC_MSG_ERROR([GeoIP library header files were found but the library was not found])
+        ])
+fi
+
+AC_SUBST(GEOIP_INCLUDE)
+AC_SUBST(GEOIP_LIB)
 
 dnl Files to create
 AC_OUTPUT([Makefile ipv6calc/Makefile man/Makefile ipv6logconv/Makefile ipv6loganon/Makefile ipv6logstats/Makefile contrib/ipv6calc.spec ipv6calcweb/ipv6calcweb.cgi ])
--- ipv6calc-0.70cvs+20070208.orig/Makefile.in
+++ ipv6calc-0.70cvs+20070208/Makefile.in
@@ -19,15 +19,6 @@
 
 CC	= gcc
 
-ifeq (@ENABLE_SUPPORT_IP2LOCATION@, 1)
-  IP2LOCATION_MAKE = ip2location-make
-endif
-ifeq (@ENABLE_SUPPORT_GEOIP@, 1)
-  ifeq (, @ENABLE_SYSTEM_GEOIP@)
-    GEOIP_MAKE = geoip-make
-  endif
-endif
-
 all:		md5-make $(GETOPT_MAKE) ipv6calc ipv6logconv ipv6loganon ipv6logstats
 
 .c.o:
@@ -46,7 +37,7 @@
 		${MAKE} clean
 		rm -f config.cache config.status config.log
 		rm -rf autom4te.cache
-		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc man lib md5 $(GETOPT_MAKE) databases/ieee-oui databases/ieee-iab databases/ipv4-assignment databases/ipv6-assignment databases/IP2Location/C-IP2Location- at VERSION_IP2LOCATION@ databases/GeoIP/GeoIP- at VERSION_GEOIP@; do \
+		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc man lib md5 $(GETOPT_MAKE) databases/ieee-oui databases/ieee-iab databases/ipv4-assignment databases/ipv6-assignment; do \
 			ocwd=`pwd`; \
 			cd $$dir || exit 1; \
 			${MAKE} $@ ; \
@@ -67,7 +58,7 @@
 		done
 
 clean:
-		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc man lib md5 $(GETOPT_MAKE) databases/IP2Location/C-IP2Location- at VERSION_IP2LOCATION@ databases/GeoIP/GeoIP- at VERSION_GEOIP@; do \
+		for dir in ipv6logconv ipv6loganon ipv6logstats ipv6calcweb ipv6calc man lib md5 $(GETOPT_MAKE); do \
 			ocwd=`pwd`; \
 			cd $$dir || exit 1; \
 			${MAKE} $@ ; \
@@ -104,7 +95,7 @@
 ipv6logstats-make: lib-make
 		cd ipv6logstats && ${MAKE}
 
-ipv6calc-make:	lib-make $(IP2LOCATION_MAKE) $(GEOIP_MAKE)
+ipv6calc-make:	lib-make
 		cd ipv6calc && ${MAKE}
 
 ipv6calcweb-make:
@@ -122,31 +113,6 @@
 db-ipv6-assignment-make:
 		cd databases/ipv6-assignment && ${MAKE}
 
-ip2location-make:
-		# check for existence of object file
-		test -f databases/IP2Location/C-IP2Location- at VERSION_IP2LOCATION@/libIP2Location/IP2Location.o || ${MAKE} ip2location-makereal
-		# check for object file newer than source file
-		test databases/IP2Location/C-IP2Location- at VERSION_IP2LOCATION@/libIP2Location/IP2Location.o -nt databases/IP2Location/C-IP2Location- at VERSION_IP2LOCATION@/libIP2Location/IP2Location.c || ${MAKE} ip2location-makereal
-
-ip2location-makereal:
-			( cd databases/IP2Location/C-IP2Location- at VERSION_IP2LOCATION@ || exit 1 ; \
-			autoreconf -i -v --force || exit 1; \
-			./configure || exit 1; \
-			${MAKE}; \
-			)
-
-geoip-make:
-		# check for existence of object file
-		test -f databases/GeoIP/GeoIP- at VERSION_GEOIP@/libGeoIP/GeoIP.o || ${MAKE} geoip-makereal
-
-geoip-makereal:
-			( cd databases/GeoIP/GeoIP- at VERSION_GEOIP@ || exit 1; \
-			./bootstrap || exit 1; \
-			./configure || exit 1; \
-			${MAKE}; \
-			${MAKE} check; \
-			)
-
 update:
 		for dir in databases/ieee-oui databases/ieee-iab databases/registries; do \
 			ocwd=`pwd`; \
--- ipv6calc-0.70cvs+20070208.orig/LICENSE
+++ ipv6calc-0.70cvs+20070208/LICENSE
@@ -20,27 +20,6 @@
 	IAB/OUI data is taken from IEEE
 	IPv4/IPv6 assignment data is taken from registries RIPE NCC, APNIC, ARIN, LACNIC, AfriNIC
 
-   * IP2Location API code
-	GPL licence: databases/IP2Location/C-IP2Location-1.1.0/COPYING
-	- databases/IP2Location/*
-
-   * IP2Location real databases
-	are NOT distributed with this package because of dedicated licensing is required
-	see here for more: http://www.ip2location.com/
-
-   * GeoIP API code
-	GPL licence: databases/GeoIP/GeoIP-1.3.17/COPYING
-	- databases/GeoIP/*
-
-   * GeoIP free databases
-	are NOT included with this package because of keeping exported package small
-	see here for more: http://www.maxmind.com/ or retrieve them directly:
-	 http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
-	 http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
-	but don't forget to read the license
-	 http://www.maxmind.com/download/geoip/database/LICENSE.txt
-
-
 1. The program "ipv6calc" is distributed under the GNU GPL version 2
     (see COPYING file for more)
 
--- ipv6calc-0.70cvs+20070208.orig/README.BUILDING-IP2LOCATION
+++ ipv6calc-0.70cvs+20070208/README.BUILDING-IP2LOCATION
@@ -0,0 +1,62 @@
+BUILDING IP2LOCATION
+--------------------
+
+If you want to use the IP2Location library with ipv6calc, you will
+have to build and install it yourself separately.  Unfortunately,
+the current version (2.1.1) of the IP2Location library distributed at
+<http://www.ip2location.com/c.aspx> is not very polished. It needs at
+least GNU automake, autoconf and libtool to build. You must first build
+the configure script, as documented in the README:
+
+% autoreconf -i -v --force
+
+Then, as normal:
+
+./configure
+
+If you get this message:
+
+configure: creating ./config.status
+config.status: error: cannot find input file: Makefile
+
+the problem is that configure.ac contains DOS-style line
+endings.
+
+An easy way to fix this is:
+
+% perl -pi.bak -e 's/\r//' configure.ac
+
+Afterwards, you'll have to rerun autoreconf:
+
+% autoreconf -i -v --force
+
+Now the normal build procedure
+
+% ./configure && make
+
+should work, but be aware that 'make install' will only
+install the library, not the include files (and even the
+library will go into a strange place). The best way to fix
+this is to edit libIP2Location/Makefile.am and change
+
+pkglib_LTLIBRARIES = libIP2Location.la
+
+into
+
+lib_LTLIBRARIES = libIP2Location.la
+include_HEADERS = IP2Location.h bigd.h
+
+So, one more iteration:
+
+% autoreconf -i -v --force
+
+% ./configure && make
+
+# make install
+
+and you should be OK. Phew!
+
+Next, see the INSTALL file in the ipv6calc distribution for information
+on configuring ipv6calc to use the library.
+
+-- Niko Tyni <ntyni at iki.fi>, Fri, 09 Feb 2007 00:23:29 +0200
--- ipv6calc-0.70cvs+20070208.orig/ipv6calc/Makefile.in
+++ ipv6calc-0.70cvs+20070208/ipv6calc/Makefile.in
@@ -13,27 +13,9 @@
 # Compiler and Linker Options
 COPTS = -O2 -Wall -g
 
-CFLAGS	= $(COPTS) @GETOPT_INCLUDE@ -I../ -I../lib/
+CFLAGS	= $(COPTS) @GETOPT_INCLUDE@ @GEOIP_INCLUDE@ @IP2LOCATION_INCLUDE@ -I../ -I../lib/
 
-GETOBJS = @LIBOBJS@ ../md5/md5.o
-
-ifeq (@ENABLE_SUPPORT_IP2LOCATION@, 1)
-  COPTS := $(COPTS) -DSUPPORT_IP2LOCATION
-  path_libIP2Location = ../databases/IP2Location/C-IP2Location- at VERSION_IP2LOCATION@/libIP2Location
-  CFLAGS := $(CFLAGS) -I$(path_libIP2Location)
-  GETOBJS := $(GETOBJS) $(path_libIP2Location)/IP2Location.o $(path_libIP2Location)/bigdigits.o $(path_libIP2Location)/spBigdigits.o $(path_libIP2Location)/bigd.o
-endif
-
-ifeq (@ENABLE_SUPPORT_GEOIP@, 1)
-  COPTS := $(COPTS) -DSUPPORT_GEOIP
-  ifeq (@ENABLE_SYSTEM_GEOIP@, 1)
-    GETOBJS := $(GETOBJS) -lGeoIP
-  else
-    path_libGeoIP = ../databases/GeoIP/GeoIP- at VERSION_GEOIP@/libGeoIP
-    CFLAGS := $(CFLAGS) -I$(path_libGeoIP)
-    GETOBJS := $(GETOBJS) $(path_libGeoIP)/GeoIP.o $(path_libGeoIP)/GeoIPCity.o
-  endif
-endif
+GETOBJS = @LIBOBJS@ ../md5/md5.o @GEOIP_LIB@ @IP2LOCATION_LIB@
 
 CC	= gcc
 
--- ipv6calc-0.70cvs+20070208.orig/ipv6calc/showinfo.c
+++ ipv6calc-0.70cvs+20070208/ipv6calc/showinfo.c
@@ -28,6 +28,14 @@
 
 #ifdef SUPPORT_IP2LOCATION
 #include "IP2Location.h"
+
+/* 
+ * API_VERSION is defined as a bareword in IP2Location.h, 
+ * we need this trick to stringify it. Blah.
+ */
+#define makestr(x) #x
+#define xmakestr(x) makestr(x)
+
 extern int use_ip2location_ipv4;
 extern int use_ip2location_ipv6;
 extern char file_ip2location_ipv4[NI_MAXHOST];
@@ -167,7 +175,7 @@
 		flag_ip2location_info_shown = 1;
 
 		if ( machinereadable != 0 ) {
-			snprintf(tempstring, sizeof(tempstring) - 1, "IP2LOCATION_DATABASE_INFO=url=http://www.ip2location.com date=%04d-%02d-%02d entries=%d apiversion=%s", IP2LocationObj->databaseyear + 2000, IP2LocationObj->databasemonth + 1, IP2LocationObj->databaseday, IP2LocationObj->databasecount, VERSION_IP2LOCATION);
+			snprintf(tempstring, sizeof(tempstring) - 1, "IP2LOCATION_DATABASE_INFO=url=http://www.ip2location.com date=%04d-%02d-%02d entries=%d apiversion=%s", IP2LocationObj->databaseyear + 2000, IP2LocationObj->databasemonth + 1, IP2LocationObj->databaseday, IP2LocationObj->databasecount, xmakestr(API_VERSION));
 			printout(tempstring);
 		};
 	};
@@ -319,11 +327,7 @@
 			flag_geoip_info_shown = 1;
 
 			if ( machinereadable != 0 ) {
-#ifdef ENABLE_GEOIP_SYSTEM
 				snprintf(tempstring, sizeof(tempstring) - 1, "GEOIP_DATABASE_INFO=%s apiversion=system", GeoIP_database_info(gi));
-#else
-				snprintf(tempstring, sizeof(tempstring) - 1, "GEOIP_DATABASE_INFO=%s apiversion=%s", GeoIP_database_info(gi), VERSION_GEOIP);
-#endif
 				printout(tempstring);
 			};
 		};


More information about the ipv6calc mailing list