Giter VIP home page Giter VIP logo

chrislim2888 / ip2location-c-library Goto Github PK

View Code? Open in Web Editor NEW
55.0 13.0 29.0 7.9 MB

IP2Location C library enables the user to find the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather station code, weather station name, mobile, usage types, etc that any IP address or hostname originates from.

Home Page: https://www.ip2location.com

License: MIT License

Shell 72.19% Perl 7.84% C 14.71% Makefile 4.10% M4 0.46% Roff 0.71%
ip2location c iplocation geolocation ip-lookup ip-address ipv4 ipv6 country region

ip2location-c-library's Introduction

IP2Location C Library

IP2Location is a C library that enables the user to find the country, region or state, district, city, latitude and longitude, ZIP/Postal code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation, usage type, address type, IAB category and ASN by IP address or hostname originates from. The library reads the geo location information from IP2Location BIN data file.

In addition to the C Library, the build process will also create an executable called "ip2location" that allows you to directly perform IP geolocation lookups. Please refer to the ip2location CLI documentation for more information. Supported IPv4 and IPv6 address.

For more details, please visit: https://www.ip2location.com/developers/c

Developer Documentation

To learn more about installation, usage, and code examples, please visit the developer documentation at https://ip2location-c-library.readthedocs.io/en/latest/index.html.

Installation

Please refer to the installation section in our documentation for instruction on how to install in various platform.

Sample BIN Databases

IPv4 BIN vs IPv6 BIN

  • Use the IPv4 BIN file if you just need to query IPv4 addresses.
  • Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

NOTES

If you encountered error while loading shared libraries in linux platform, that could be due to the shared library was saved into usr/local/lib that might not be the default library path. You can run the below command

ldconfig /usr/local/lib

IP2Location CLI

Query an IP address and display the result

ip2location -d [IP2LOCATION BIN DATA PATH] --ip [IP ADDRESS]

Query all IP addresses from an input file and display the result

ip2location -d [IP2LOCATION BIN DATA PATH] -i [INPUT FILE PATH]

Query all IP addresses from an input file and display the result in XML format

ip2location -d [IP2LOCATION BIN DATA PATH] -i [INPUT FILE PATH] --format XML

References

Address Type

Address type is the IP address types as defined in Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6). The database return a single character. For the full description, please refer to list below:

  • (A) Anycast - One to the closest
  • (U) Unicast - One to one
  • (M) Multicast - One to multiple
  • (B) Broadcast - One to all
Category

Category is the domain category is based on IAB Tech Lab Content Taxonomy. These categories are comprised of Tier-1 and Tier-2 (if available) level categories widely used in services like advertising, Internet security and filtering appliances. Please refer to https://www.ip2location.com/free/iab-categories for the full list.

Packages for Fedora/Enterprise Linux can be found here

Support

Email: [email protected].
URL: https://www.ip2location.com

ip2location-c-library's People

Contributors

chrislim2888 avatar droberson avatar erankor avatar gvanem avatar ip2location avatar lytboris avatar pbiering avatar remicollet avatar wi24rd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ip2location-c-library's Issues

segfault

Any idea how to tackle this kind of error? Library is used in nginx module under moderate load.

Nov 7 10:42:18 hc01 kernel: [592271.864154] nginx[23867]: segfault at 13c22ca91 ip 00007fa94d22dee6 sp 00007ffe7ea5a660 error 4 in libIP2Location.so.1.0.0[7fa94d22a000+5000]

cmake support

Hello,

Thanks for the nice API ;)

It would be nice to have here also cmake support which will make bundling (and having submodule) a little bit easier.

error during autoreconf with v8.0.7

When I try to install the library v8.0.7, autoreconf fails with an error below

Makefile.am: error: required file './README' not found
autoreconf: automake failed with exit status: 1

Which does not appear in master branch.

Please consider releasing a new release v8.0.8 if this issue has been fixed.

Leak in IP2Location_get_elevation()

The code for this call will do:

if ((mode & ELEVATION) && (ELEVATION_POSITION[dbtype] != 0))
{
  record->elevation = atof(IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 
                                       4 * (ELEVATION_POSITION[dbtype]-1))));
}

But IP2Location_readStr() calls malloc() to get at this Pascal-type string.
And this memory never gets freed.

A fix could be to add a IP2LocationRecord / char *elevation_mem element to free() in IP2Location_free_record()?

Makefile.win broken

What? No issues. Okay, I'll make the first.

The Makefile.win makefile does not define a PACKAGE_VERSION. Issuing nmake -f Makefile.win, yields:

libIP2Location/IP2Location.c(782): error C2065: 'PACKAGE_VERSION': undeclared identifier
libIP2Location/IP2Location.c(782): warning C4047: 'return': 'char *' differs in levels of indirection from 'int'

It's not really obvious to me what this version should be. But from the Changelog and API_VERSION_NUMERIC, I assume 8.0.4.

BTW. I rewrote Makefile.win into something more readable: https://gist.github.com/gvanem/de1530d2b3f8e3d109fc876dd8174057

Please tag releases

According to changelog 8.0.3 is the last valid version but on https://www.ip2location.com/developers/c there is only a reference to "master". Please tag this release proper to make a consistent download later of 8.0.3 possible (and if possible/senseful, please tag releases < 8.0.1 also), currently, only 8.0.1 and 8.0.2 are tagged - thank you!

IP2Location.c windows installation error Fix

/*
 * IP2Location C library is distributed under MIT license
 * Copyright (c) 2013-2024 IP2Location.com. support at ip2location dot com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the MIT license
 */

#ifdef WIN32
	#include <winsock2.h>
	#include <ws2tcpip.h>
#else
	#include <stdint.h>
	#include <strings.h>
	#include <sys/socket.h>
	#include <netinet/in.h>
	#include <arpa/inet.h>
	#include <unistd.h>
	#include <sys/mman.h>
#endif

#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stddef.h>

#include "IP2Location.h"

#ifdef _WIN32
	#define _STR2(x) #x
	#define _STR(x) _STR2(x)
	#define PACKAGE_VERSION _STR(API_VERSION)
	#include <tchar.h>
#else
	#include "../config.h"
#endif

typedef struct ip_container {
	uint32_t version;
	uint32_t ipv4;
	struct in6_addr ipv6;
} ip_container;

uint8_t COUNTRY_POSITION[27]			= {0,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2};
uint8_t REGION_POSITION[27]				= {0,  0,  0,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3};
uint8_t CITY_POSITION[27]				= {0,  0,  0,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4};
uint8_t LATITUDE_POSITION[27]			= {0,  0,  0,  0,  0,  5,  5,  0,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5};
uint8_t LONGITUDE_POSITION[27]			= {0,  0,  0,  0,  0,  6,  6,  0,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6};
uint8_t ZIPCODE_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  7,  7,  7,  7,  0,  7,  7,  7,  0,  7,  0,  7,  7,  7,  0,  7,  7,  7};
uint8_t TIMEZONE_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  8,  8,  7,  8,  8,  8,  7,  8,  0,  8,  8,  8,  0,  8,  8,  8};
uint8_t ISP_POSITION[27]				= {0,  0,  3,  0,  5,  0,  7,  5,  7,  0,  8,  0,  9,  0,  9,  0,  9,  0,  9,  7,  9,  0,  9,  7,  9,  9,  9};
uint8_t DOMAIN_POSITION[27]				= {0,  0,  0,  0,  0,  0,  0,  6,  8,  0,  9,  0, 10,  0, 10,  0, 10,  0, 10,  8, 10,  0, 10,  8, 10, 10, 10};
uint8_t NETSPEED_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  8, 11,  0, 11,  8, 11,  0, 11,  0, 11,  0, 11, 11, 11};
uint8_t IDDCODE_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  9, 12,  0, 12,  0, 12,  9, 12,  0, 12, 12, 12};
uint8_t AREACODE_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 10, 13,  0, 13,  0, 13, 10, 13,  0, 13, 13, 13};
uint8_t WEATHERSTATIONCODE_POSITION[27]	= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  9, 14,  0, 14,  0, 14,  0, 14, 14, 14};
uint8_t WEATHERSTATIONNAME_POSITION[27]	= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 10, 15,  0, 15,  0, 15,  0, 15, 15, 15};
uint8_t MCC_POSITION[27]				= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  9, 16,  0, 16,  9, 16, 16, 16};
uint8_t MNC_POSITION[27]				= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 10, 17,  0, 17, 10, 17, 17, 17};
uint8_t MOBILEBRAND_POSITION[27]		= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 11, 18,  0, 18, 11, 18, 18, 18};
uint8_t ELEVATION_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 11, 19,  0, 19, 19, 19};
uint8_t USAGETYPE_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 12, 20, 20, 20};
uint8_t ADDRESSTYPE_POSITION[27]		= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 21, 21};
uint8_t CATEGORY_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 22, 22};
uint8_t DISTRICT_POSITION[27]			= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23};
uint8_t ASN_POSITION[27]				= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 24};
uint8_t AS_POSITION[27]					= {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 25};

// Static variables
static int32_t is_in_memory = 0;
static enum IP2Location_lookup_mode lookup_mode = IP2LOCATION_FILE_IO; /* Set default lookup mode as File I/O */
//static void *memory_pointer; --removed

// Static functions
static int IP2Location_initialize(IP2Location *handler);
static int IP2Location_is_ipv4(char *ip);
static int IP2Location_is_ipv6(char *ip);
static int32_t IP2Location_load_database_into_memory(FILE *file, void *memory_pointer, int64_t size);
static IP2LocationRecord *IP2Location_new_record();
static IP2LocationRecord *IP2Location_get_record(IP2Location *handler, char *ip, uint32_t mode);
static IP2LocationRecord *IP2Location_get_ipv4_record(IP2Location *handler, uint32_t mode, ip_container parsed_ip);
static IP2LocationRecord *IP2Location_get_ipv6_record(IP2Location *handler, uint32_t mode, ip_container parsed_ip);

extern int lookup_mode; //added
uint8_t* memory_pointer; //added

#ifndef WIN32
static int32_t shm_fd;
#else
#ifdef WIN32
HANDLE shm_fd;
#endif
#endif

// Open IP2Location BIN database file
IP2Location *IP2Location_open(char *bin)
{
	FILE *f;
	IP2Location *handler;

	if ((f = fopen(bin, "rb")) == NULL) {
		printf("IP2Location library error in opening database %s.\n", bin);
		return NULL;
	}

	handler = (IP2Location *) calloc(1, sizeof(IP2Location));
	if (handler == NULL) {
		fclose(f);
		return NULL;
	}
	handler->file = f;

	IP2Location_initialize(handler);

	if (handler->product_code == 1) {
		return handler;
	}

	if (handler->database_year <= 20 && handler->product_code == 0) {
		return handler;
	}

	printf(INVALID_BIN_DATABASE);
	fclose(f);
	free(handler);
	return NULL;
}

// Initialize database structures
static int IP2Location_initialize(IP2Location *handler)
{
	uint8_t buffer[64];
	uint32_t mem_offset = 1;

	if (lookup_mode == IP2LOCATION_FILE_IO) {
		fread(buffer, sizeof(buffer), 1, handler->file);
	}

	handler->database_type = IP2Location_read8_row((uint8_t*)buffer, 0, mem_offset);
	handler->database_column = IP2Location_read8_row((uint8_t*)buffer, 1, mem_offset);
	handler->database_year = IP2Location_read8_row((uint8_t*)buffer, 2, mem_offset);
	handler->database_month = IP2Location_read8_row((uint8_t*)buffer, 3, mem_offset);
	handler->database_day = IP2Location_read8_row((uint8_t*)buffer, 4, mem_offset);
	handler->database_count = IP2Location_read32_row((uint8_t*)buffer, 5, mem_offset);
	handler->database_address = IP2Location_read32_row((uint8_t*)buffer, 9, mem_offset);
	handler->ip_version = IP2Location_read32_row((uint8_t*)buffer, 13, mem_offset);
	handler->ipv4_database_count = IP2Location_read32_row((uint8_t*)buffer, 5, mem_offset);
	handler->ipv4_database_address = IP2Location_read32_row((uint8_t*)buffer, 9, mem_offset);
	handler->ipv6_database_count = IP2Location_read32_row((uint8_t*)buffer, 13, mem_offset);
	handler->ipv6_database_address = IP2Location_read32_row((uint8_t*)buffer, 17, mem_offset);
	handler->ipv4_index_base_address = IP2Location_read32_row((uint8_t*)buffer, 21, mem_offset);
	handler->ipv6_index_base_address = IP2Location_read32_row((uint8_t*)buffer, 25, mem_offset);
	handler->product_code = IP2Location_read8_row((uint8_t*)buffer, 29, mem_offset);
	handler->license_code = IP2Location_read8_row((uint8_t*)buffer, 30, mem_offset);
	handler->database_size = IP2Location_read32_row((uint8_t*)buffer, 31, mem_offset);

	return 0;
}

// This function to set the DB access type.
int32_t IP2Location_open_mem(IP2Location *handler, enum IP2Location_lookup_mode mode)
{
	// BIN database is not loaded
	if (handler == NULL) {
		return -1;
	}

	// Existing database already loaded into memory
	if (is_in_memory != 0) {
		return -1;
	}

	// Mark database loaded into memory
	is_in_memory = 1;

	if (mode == IP2LOCATION_FILE_IO) {
		return 0;
	} else if (mode == IP2LOCATION_CACHE_MEMORY) {
		return IP2Location_DB_set_memory_cache(handler->file);
	} else if (mode == IP2LOCATION_SHARED_MEMORY) {
		return IP2Location_DB_set_shared_memory(handler->file);
	} else {
		return -1;
	}
}

// Alias to IP2Location_open_mem()
int32_t IP2Location_set_lookup_mode(IP2Location *handler, enum IP2Location_lookup_mode mode)
{
	return IP2Location_open_mem(handler, mode);
}

// Close the IP2Location database file
uint32_t IP2Location_close(IP2Location *handler)
{
	is_in_memory = 0;

	if (handler != NULL) {
		IP2Location_DB_close(handler->file);
		free(handler);
	}

	return 0;
}

// Delete IP2Location shared memory if its present
void IP2Location_delete_shm()
{
    IP2Location_DB_del_shm();
}

// Alias to IP2Location_delete_shm()
void IP2Location_clear_memory()
{
	IP2Location_delete_shm();
}

// Alias to IP2Location_DB_del_shm()
void IP2Location_delete_shared_memory()
{
	IP2Location_DB_del_shm();
}

// Compare IPv6 address
int ipv6_compare(struct in6_addr *addr1, struct in6_addr *addr2)
{
	int i, ret = 0;
	for (i = 0; i < 16; i++) {
		if (addr1->s6_addr[i] > addr2->s6_addr[i]) {
			ret = 1;
			break;
		} else if (addr1->s6_addr[i] < addr2->s6_addr[i]) {
			ret = -1;
			break;
		}
	}

	return ret;
}

// Alias to
int IP2Location_ipv6_compare(struct in6_addr *addr1, struct in6_addr *addr2)
{
	return ipv6_compare(addr1, addr2);
}

// Parse IP address into binary address for lookup purpose
static ip_container IP2Location_parse_address(const char *ip)
{
	ip_container parsed;

	if (IP2Location_is_ipv4((char *) ip)) {
		// Parse IPv4 address
		parsed.version = 4;
		inet_pton(AF_INET, ip, &parsed.ipv4);
		parsed.ipv4 = htonl(parsed.ipv4);
	} else if (IP2Location_is_ipv6((char *) ip)) {
		// Parse IPv6 address
		inet_pton(AF_INET6, ip, &parsed.ipv6);

		// IPv4 Address in IPv6
		if (parsed.ipv6.s6_addr[0] == 0 && parsed.ipv6.s6_addr[1] == 0 && parsed.ipv6.s6_addr[2] == 0 && parsed.ipv6.s6_addr[3] == 0 && parsed.ipv6.s6_addr[4] == 0 && parsed.ipv6.s6_addr[5] == 0 && parsed.ipv6.s6_addr[6] == 0 && parsed.ipv6.s6_addr[7] == 0 && parsed.ipv6.s6_addr[8] == 0 && parsed.ipv6.s6_addr[9] == 0 && parsed.ipv6.s6_addr[10] == 255 && parsed.ipv6.s6_addr[11] == 255) {
			parsed.version = 4;
			parsed.ipv4 = (parsed.ipv6.s6_addr[12] << 24) + (parsed.ipv6.s6_addr[13] << 16) + (parsed.ipv6.s6_addr[14] << 8) + parsed.ipv6.s6_addr[15];
		}

		// 6to4 Address - 2002::/16
		else if (parsed.ipv6.s6_addr[0] == 32 && parsed.ipv6.s6_addr[1] == 2) {
			parsed.version = 4;
			parsed.ipv4 = (parsed.ipv6.s6_addr[2] << 24) + (parsed.ipv6.s6_addr[3] << 16) + (parsed.ipv6.s6_addr[4] << 8) + parsed.ipv6.s6_addr[5];
		}

		// Teredo Address - 2001:0::/32
		else if (parsed.ipv6.s6_addr[0] == 32 && parsed.ipv6.s6_addr[1] == 1 && parsed.ipv6.s6_addr[2] == 0 && parsed.ipv6.s6_addr[3] == 0) {
			parsed.version = 4;
			parsed.ipv4 = ~((parsed.ipv6.s6_addr[12] << 24) + (parsed.ipv6.s6_addr[13] << 16) + (parsed.ipv6.s6_addr[14] << 8) + parsed.ipv6.s6_addr[15]);
		}

		// Common IPv6 Address
		else {
			parsed.version = 6;
		}
	} else {
		// Invalid IP address
		parsed.version = -1;
	}

	return parsed;
}

// Get country code
IP2LocationRecord *IP2Location_get_country_short(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, COUNTRYSHORT);
}

// Get country name
IP2LocationRecord *IP2Location_get_country_long(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, COUNTRYLONG);
}

// Get the name of state/region
IP2LocationRecord *IP2Location_get_region(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, REGION);
}

// Get city name
IP2LocationRecord *IP2Location_get_city(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, CITY);
}

// Get ISP name
IP2LocationRecord *IP2Location_get_isp(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, ISP);
}

// Get latitude
IP2LocationRecord *IP2Location_get_latitude(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, LATITUDE);
}

// Get longitude
IP2LocationRecord *IP2Location_get_longitude(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, LONGITUDE);
}

// Get domain name
IP2LocationRecord *IP2Location_get_domain(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, DOMAINNAME);
}

// Get ZIP code
IP2LocationRecord *IP2Location_get_zipcode(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, ZIPCODE);
}

// Get time zone
IP2LocationRecord *IP2Location_get_timezone(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, TIMEZONE);
}

// Get net speed
IP2LocationRecord *IP2Location_get_netspeed(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, NETSPEED);
}

// Get IDD code
IP2LocationRecord *IP2Location_get_iddcode(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, IDDCODE);
}

// Get area code
IP2LocationRecord *IP2Location_get_areacode(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, AREACODE);
}

// Get weather station code
IP2LocationRecord *IP2Location_get_weatherstationcode(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, WEATHERSTATIONCODE);
}

// Get weather station name
IP2LocationRecord *IP2Location_get_weatherstationname(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, WEATHERSTATIONNAME);
}

// Get mobile country code
IP2LocationRecord *IP2Location_get_mcc(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, MCC);
}

// Get mobile national code
IP2LocationRecord *IP2Location_get_mnc(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, MNC);
}

// Get mobile carrier brand
IP2LocationRecord *IP2Location_get_mobilebrand(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, MOBILEBRAND);
}

// Get elevation
IP2LocationRecord *IP2Location_get_elevation(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, ELEVATION);
}

// Get usage type
IP2LocationRecord *IP2Location_get_usagetype(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, USAGETYPE);
}

// Get address type
IP2LocationRecord *IP2Location_get_addresstype(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, ADDRESSTYPE);
}

// Get category
IP2LocationRecord *IP2Location_get_category(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, CATEGORY);
}

// Get district
IP2LocationRecord *IP2Location_get_district(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, DISTRICT);
}

// Get ASN
IP2LocationRecord *IP2Location_get_asn(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, ASN);
}

// Get AS
IP2LocationRecord *IP2Location_get_as(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, AS);
}

// Get all records of an IP address
IP2LocationRecord *IP2Location_get_all(IP2Location *handler, char *ip)
{
	return IP2Location_get_record(handler, ip, ALL);
}

// fill the record fields with error message
static IP2LocationRecord *IP2Location_bad_record(const char *message)
{
	IP2LocationRecord *record = IP2Location_new_record();
	record->country_short = strdup(message);
	record->country_long = strdup(message);
	record->region = strdup(message);
	record->city = strdup(message);
	record->isp = strdup(message);
	record->domain = strdup(message);
	record->zipcode = strdup(message);
	record->timezone = strdup(message);
	record->netspeed = strdup(message);
	record->iddcode = strdup(message);
	record->areacode = strdup(message);
	record->weatherstationcode = strdup(message);
	record->weatherstationname = strdup(message);
	record->mcc = strdup(message);
	record->mnc = strdup(message);
	record->mobilebrand = strdup(message);
	record->usagetype = strdup(message);

	record->latitude = 0;
	record->longitude = 0;
	record->elevation = 0;

	record->address_type = strdup(message);
	record->category = strdup(message);
	record->district = strdup(message);
	record->asn = strdup(message);
	record->as = strdup(message);

	return record;
}

static IP2LocationRecord *IP2Location_read_record(IP2Location *handler, uint8_t* buffer, uint32_t mode, uint32_t mem_offset) {
	uint8_t database_type = handler->database_type;
	FILE *handle = handler->file;
	IP2LocationRecord *record = IP2Location_new_record();

	if ((mode & COUNTRYSHORT) && (COUNTRY_POSITION[database_type] != 0)) {
		if (!record->country_short) {
			record->country_short = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (COUNTRY_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->country_short) {
			record->country_short = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & COUNTRYLONG) && (COUNTRY_POSITION[database_type] != 0)) {
		if (!record->country_long) {
			record->country_long = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (COUNTRY_POSITION[database_type] - 2), mem_offset) + 3);
		}
	} else {
		if (!record->country_long) {
			record->country_long = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & REGION) && (REGION_POSITION[database_type] != 0)) {
		if (!record->region) {
			record->region = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (REGION_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->region) {
			record->region = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & CITY) && (CITY_POSITION[database_type] != 0)) {
		if (!record->city) {
			record->city = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (CITY_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->city) {
			record->city = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & ISP) && (ISP_POSITION[database_type] != 0)) {
		if (!record->isp) {
			record->isp = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (ISP_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->isp) {
			record->isp = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & LATITUDE) && (LATITUDE_POSITION[database_type] != 0)) {
		record->latitude = IP2Location_read_float_row(buffer, 4 * (LATITUDE_POSITION[database_type] - 2), mem_offset);
	} else {
		record->latitude = 0.0;
	}

	if ((mode & LONGITUDE) && (LONGITUDE_POSITION[database_type] != 0)) {
		record->longitude = IP2Location_read_float_row(buffer, 4 * (LONGITUDE_POSITION[database_type] - 2), mem_offset);
	} else {
		record->longitude = 0.0;
	}

	if ((mode & DOMAINNAME) && (DOMAIN_POSITION[database_type] != 0)) {
		if (!record->domain) {
			record->domain = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (DOMAIN_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->domain) {
			record->domain = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & ZIPCODE) && (ZIPCODE_POSITION[database_type] != 0)) {
		if (!record->zipcode) {
			record->zipcode = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (ZIPCODE_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->zipcode) {
			record->zipcode = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & TIMEZONE) && (TIMEZONE_POSITION[database_type] != 0)) {
		if (!record->timezone) {
			record->timezone = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (TIMEZONE_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->timezone) {
			record->timezone = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & NETSPEED) && (NETSPEED_POSITION[database_type] != 0)) {
		if (!record->netspeed) {
			record->netspeed = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (NETSPEED_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->netspeed) {
			record->netspeed = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & IDDCODE) && (IDDCODE_POSITION[database_type] != 0)) {
		if (!record->iddcode) {
			record->iddcode = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (IDDCODE_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->iddcode) {
			record->iddcode = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & AREACODE) && (AREACODE_POSITION[database_type] != 0)) {
		if (!record->areacode) {
			record->areacode = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (AREACODE_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->areacode) {
			record->areacode = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & WEATHERSTATIONCODE) && (WEATHERSTATIONCODE_POSITION[database_type] != 0)) {
		if (!record->weatherstationcode) {
			record->weatherstationcode = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (WEATHERSTATIONCODE_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->weatherstationcode) {
			record->weatherstationcode = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & WEATHERSTATIONNAME) && (WEATHERSTATIONNAME_POSITION[database_type] != 0)) {
		if (!record->weatherstationname) {
			record->weatherstationname = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (WEATHERSTATIONNAME_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->weatherstationname) {
			record->weatherstationname = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & MCC) && (MCC_POSITION[database_type] != 0)) {
		if (!record->mcc) {
			record->mcc = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (MCC_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->mcc) {
			record->mcc = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & MNC) && (MNC_POSITION[database_type] != 0)) {
		if (!record->mnc) {
			record->mnc = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (MNC_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->mnc) {
			record->mnc = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & MOBILEBRAND) && (MOBILEBRAND_POSITION[database_type] != 0)) {
		if (!record->mobilebrand) {
			record->mobilebrand = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (MOBILEBRAND_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->mobilebrand) {
			record->mobilebrand = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & ELEVATION) && (ELEVATION_POSITION[database_type] != 0)) {
		char * mem = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (ELEVATION_POSITION[database_type] - 2), mem_offset));
		record->elevation = atof(mem);
		free(mem);
	} else {
		record->elevation = 0.0;
	}

	if ((mode & USAGETYPE) && (USAGETYPE_POSITION[database_type] != 0)) {
		if (!record->usagetype) {
			record->usagetype = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (USAGETYPE_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->usagetype) {
			record->usagetype = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & ADDRESSTYPE) && (ADDRESSTYPE_POSITION[database_type] != 0)) {
		if (!record->address_type) {
			record->address_type = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (ADDRESSTYPE_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->address_type) {
			record->address_type = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & CATEGORY) && (CATEGORY_POSITION[database_type] != 0)) {
		if (!record->category) {
			record->category = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (CATEGORY_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->category) {
			record->category = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & DISTRICT) && (DISTRICT_POSITION[database_type] != 0)) {
		if (!record->district) {
			record->district = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (DISTRICT_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->district) {
			record->district = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & ASN) && (ASN_POSITION[database_type] != 0)) {
		if (!record->asn) {
			record->asn = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (ASN_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->asn) {
			record->asn = strdup(NOT_SUPPORTED);
		}
	}

	if ((mode & AS) && (AS_POSITION[database_type] != 0)) {
		if (!record->as) {
			record->as = IP2Location_read_string(handle, IP2Location_read32_row(buffer, 4 * (AS_POSITION[database_type] - 2), mem_offset));
		}
	} else {
		if (!record->as) {
			record->as = strdup(NOT_SUPPORTED);
		}
	}

	return record;
}

// Get record for a IPv6 from database
static IP2LocationRecord * IP2Location_get_ipv6_record(IP2Location *handler, uint32_t mode, ip_container parsed_ip) {
	FILE * handle = handler->file;
	uint32_t base_address = handler->ipv6_database_address;
	uint32_t database_column = handler->database_column;
	uint32_t ipv6_index_base_address = handler->ipv6_index_base_address;

	uint32_t low = 0;
	uint32_t high = handler->ipv6_database_count;
	uint32_t mid = 0;

	struct in6_addr ip_from;
	struct in6_addr ip_to;
	struct in6_addr ip_number;

	uint32_t column_offset = database_column * 4 + 12;
	uint32_t row_offset = 0;
	uint8_t full_row_buffer[200];
	uint8_t row_buffer[200];
	uint32_t full_row_size;
	uint32_t row_size;
	uint32_t mem_offset;

	ip_number = parsed_ip.ipv6;

	if (!high) {
		return NULL;
	}

	if (ipv6_index_base_address > 0) {
		uint32_t ipnum1 = (ip_number.s6_addr[0] * 256) + ip_number.s6_addr[1];
		uint32_t indexpos = ipv6_index_base_address + (ipnum1 << 3);

		uint8_t indexbuffer[8];
		if (lookup_mode == IP2LOCATION_FILE_IO) {
			fseek(handle, indexpos - 1, 0);
			fread(indexbuffer, sizeof(indexbuffer), 1, handle);
		}
		mem_offset = indexpos;
		low = IP2Location_read32_row((uint8_t*)indexbuffer, 0, mem_offset);
		high = IP2Location_read32_row((uint8_t*)indexbuffer, 4, mem_offset);
	}

	full_row_size = column_offset + 16;
	row_size = column_offset - 16;

	while (low <= high) {
		mid = (uint32_t)((low + high) >> 1);
		row_offset = base_address + (mid * column_offset);

		if (lookup_mode == IP2LOCATION_FILE_IO) {
			fseek(handle, row_offset - 1, 0);
			fread(&full_row_buffer, full_row_size, 1, handle);
		}
		mem_offset = row_offset;

		ip_from = IP2Location_read128_row((uint8_t *)full_row_buffer, 0, mem_offset);
		ip_to = IP2Location_read128_row((uint8_t *)full_row_buffer, column_offset, mem_offset);

		if ((IP2Location_ipv6_compare(&ip_number, &ip_from) >= 0) && (IP2Location_ipv6_compare(&ip_number, &ip_to) < 0)) {
			if (lookup_mode == IP2LOCATION_FILE_IO) {
				memcpy(&row_buffer, ((uint8_t*)full_row_buffer) + 16, row_size); // extract actual row data
			}
			return IP2Location_read_record(handler, (uint8_t *)row_buffer, mode, mem_offset + 16);
		} else {
			if (IP2Location_ipv6_compare(&ip_number, &ip_from) < 0) {
				high = mid - 1;
			} else {
				low = mid + 1;
			}
		}
	}

	return NULL;
}

// Get record for a IPv4 from database
static IP2LocationRecord *IP2Location_get_ipv4_record(IP2Location *handler, uint32_t mode, ip_container parsed_ip) {
	FILE *handle = handler->file;
	uint32_t base_address = handler->ipv4_database_address;
	uint32_t database_column = handler->database_column;
	uint32_t ipv4_index_base_address = handler->ipv4_index_base_address;

	uint32_t low = 0;
	uint32_t high = handler->ipv4_database_count;
	uint32_t mid = 0;

	uint32_t ip_number;
	uint32_t ip_from;
	uint32_t ip_to;

	uint32_t column_offset = database_column * 4;
	uint32_t row_offset = 0;
	uint8_t full_row_buffer[200];
	uint8_t row_buffer[200];
	uint32_t full_row_size;
	uint32_t row_size;
	uint32_t mem_offset;

	ip_number = parsed_ip.ipv4;

	if (ip_number == (uint32_t) MAX_IPV4_RANGE) {
		ip_number = ip_number - 1;
	}

	if (ipv4_index_base_address > 0) {
		uint32_t ipnum1n2 = (uint32_t) ip_number >> 16;
		uint32_t indexpos = ipv4_index_base_address + (ipnum1n2 << 3);

		uint8_t indexbuffer[8];
		if (lookup_mode == IP2LOCATION_FILE_IO) {
			fseek(handle, indexpos - 1, 0);
			fread(indexbuffer, sizeof(indexbuffer), 1, handle);
		}
		mem_offset = indexpos;
		low = IP2Location_read32_row((uint8_t*)indexbuffer, 0, mem_offset);
		high = IP2Location_read32_row((uint8_t*)indexbuffer, 4, mem_offset);
	}

	full_row_size = column_offset + 4;
	row_size = column_offset - 4;

	while (low <= high) {
		mid = (uint32_t)((low + high) >> 1);
		row_offset = base_address + (mid * column_offset);

		if (lookup_mode == IP2LOCATION_FILE_IO) {
			fseek(handle, row_offset - 1, 0);
			fread(&full_row_buffer, full_row_size, 1, handle);
		}
		mem_offset = row_offset;

		ip_from = IP2Location_read32_row((uint8_t*)full_row_buffer, 0, mem_offset);
		ip_to = IP2Location_read32_row((uint8_t*)full_row_buffer, column_offset, mem_offset);

		if ((ip_number >= ip_from) && (ip_number < ip_to)) {
			if (lookup_mode == IP2LOCATION_FILE_IO) {
				memcpy(&row_buffer, ((uint8_t*)full_row_buffer) + 4, row_size); // extract actual row data
			}
			return IP2Location_read_record(handler, (uint8_t *)row_buffer, mode, mem_offset + 4);
		} else {
			if (ip_number < ip_from) {
				high = mid - 1;
			} else {
				low = mid + 1;
			}
		}
	}
	return NULL;
}

// Get the location data
static IP2LocationRecord *IP2Location_get_record(IP2Location *handler, char *ip, uint32_t mode) {
	ip_container parsed_ip = IP2Location_parse_address(ip);

	if (parsed_ip.version == 4) {
		return IP2Location_get_ipv4_record(handler, mode, parsed_ip);
	}
	if (parsed_ip.version == 6) {
		if (handler->ipv6_database_count == 0) {
			return IP2Location_bad_record(IPV6_ADDRESS_MISSING_IN_IPV4_BIN);
		}

		return IP2Location_get_ipv6_record(handler, mode, parsed_ip);
	} else {
		return IP2Location_bad_record(INVALID_IP_ADDRESS);
	}
}

// Initialize the record object
static IP2LocationRecord *IP2Location_new_record()
{
	IP2LocationRecord *record = (IP2LocationRecord *) calloc(1, sizeof(IP2LocationRecord));
	return record;
}

// Free the record object
void IP2Location_free_record(IP2LocationRecord *record) {
	if (record == NULL) {
		return;
	}

	free(record->city);
	free(record->country_long);
	free(record->country_short);
	free(record->domain);
	free(record->isp);
	free(record->region);
	free(record->zipcode);
	free(record->timezone);
	free(record->netspeed);
	free(record->iddcode);
	free(record->areacode);
	free(record->weatherstationcode);
	free(record->weatherstationname);
	free(record->mcc);
	free(record->mnc);
	free(record->mobilebrand);
	free(record->usagetype);
	free(record->address_type);
	free(record->category);
	free(record->district);
	free(record->asn);
	free(record->as);

	free(record);
}

// Check if address is IPv4
static int IP2Location_is_ipv4(char *ip)
{
	struct sockaddr_in sa;
	return inet_pton(AF_INET, ip, &sa.sin_addr);
}

// Check if address is IPv6
static int IP2Location_is_ipv6(char *ip)
{
	struct in6_addr result;
	return inet_pton(AF_INET6, ip, &result);
}

// Get API version numeric (Will deprecate in coming major version update)
unsigned long int IP2Location_api_version_num(void)
{
	return (API_VERSION_NUMERIC);
}

// Alias to IP2Location_api_version_num()
unsigned long int IP2Location_api_version_number(void)
{
	return IP2Location_api_version_num();
}

// Get API version as string
char *IP2Location_api_version_string(void)
{
	static char version[64];
	sprintf(version, "%d.%d.%d", API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_RELEASE);
	return (version);
}

// Get library version as string
char *IP2Location_lib_version_string(void)
{
	return (PACKAGE_VERSION);
}

// Get BIN database version
char *IP2Location_bin_version(IP2Location *handler)
{
	if (handler == NULL) {
		return NULL;
	}

	static char version[64];

	sprintf(version, "%d-%d-%d", handler->database_year + 2000, handler->database_month, handler->database_day);

	return (version);
}

// Set to use memory caching
int32_t IP2Location_DB_set_memory_cache(FILE *file)
{
	struct stat buffer;
	lookup_mode = IP2LOCATION_CACHE_MEMORY;

	if (fstat(fileno(file), &buffer) == -1) {
		lookup_mode = IP2LOCATION_FILE_IO;
		return -1;
	}

	if ((memory_pointer = malloc(buffer.st_size + 1)) == NULL) {
		lookup_mode = IP2LOCATION_FILE_IO;
		return -1;
	}

	if (IP2Location_load_database_into_memory(file, memory_pointer, buffer.st_size) == -1) {
		lookup_mode = IP2LOCATION_FILE_IO;
		free(memory_pointer);
		return -1;
	}

	return 0;
}

// Alias to IP2Location_DB_set_memory_cache()
int32_t IP2Location_set_memory_cache(FILE *file)
{
	return IP2Location_DB_set_memory_cache(file);
}

// Return the shared-memory name
#ifndef WIN32
static const char *get_shm_name(void) {
	static char name[64] = "";

	if (!name[0]) {
		sprintf(name, "/%s_%ld", IP2LOCATION_SHM, (long)getpid());
	}
	return name;
}

// Set to use shared memory
int32_t IP2Location_DB_set_shared_memory(FILE *file)
{
	struct stat buffer;
	int32_t is_dababase_loaded = 1;
	void *addr = (void*)MAP_ADDR;

	lookup_mode = IP2LOCATION_SHARED_MEMORY;

	// New shared memory object is created
	if ((shm_fd = shm_open(get_shm_name(), O_RDWR | O_CREAT | O_EXCL, 0777)) != -1) {
		is_dababase_loaded = 0;
	}

	// Failed to create new shared memory object
	else if ((shm_fd = shm_open(get_shm_name(), O_RDWR , 0777)) == -1) {
		lookup_mode = IP2LOCATION_FILE_IO;
		return -1;
	}

	if (fstat(fileno(file), &buffer) == -1) {
		close(shm_fd);

		if (is_dababase_loaded == 0) {
			shm_unlink(get_shm_name());
		}

		lookup_mode = IP2LOCATION_FILE_IO;

		return -1;
	}

	if (is_dababase_loaded == 0 && ftruncate(shm_fd, buffer.st_size + 1) == -1) {
		close(shm_fd);
		shm_unlink(get_shm_name());
		lookup_mode = IP2LOCATION_FILE_IO;
		return -1;
	}

	memory_pointer = mmap(addr, buffer.st_size + 1, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);

	if (memory_pointer == (void *) -1) {
		close(shm_fd);

		if (is_dababase_loaded == 0) {
			shm_unlink(get_shm_name());
		}

		lookup_mode = IP2LOCATION_FILE_IO;

		return -1;
	}

	if (is_dababase_loaded == 0) {
		if (IP2Location_load_database_into_memory(file, memory_pointer, buffer.st_size) == -1) {
			munmap(memory_pointer, buffer.st_size);
			close(shm_fd);
			shm_unlink(get_shm_name());
			lookup_mode = IP2LOCATION_FILE_IO;
			return -1;
		}
	}

	return 0;
}
#else
#ifdef WIN32
// Return a name for the shared-memory object
// For Windows, this depends on whether 'UNICODE' is defined
// (hence the use of 'TCHAR').
static const TCHAR *get_shm_name(void) {
	static TCHAR name[64] = _T("");

	if (!name[0]) {
		_sntprintf(name, sizeof(name)/sizeof(name[0]), _T("%s_%lu"),
                   _T(IP2LOCATION_SHM), GetProcessId(NULL));
	}
	return name;
}

int32_t IP2Location_DB_set_shared_memory(FILE *file)
{
	struct stat buffer;
	int32_t is_dababase_loaded = 1;

	lookup_mode = IP2LOCATION_SHARED_MEMORY;

	if (fstat(fileno(file), &buffer) == -1) {
		lookup_mode = IP2LOCATION_FILE_IO;
		return -1;
	}

	shm_fd = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, buffer.st_size + 1, get_shm_name());

	if (shm_fd == NULL) {
		lookup_mode = IP2LOCATION_FILE_IO;
		return -1;
	}

	is_dababase_loaded = (GetLastError() == ERROR_ALREADY_EXISTS);
	memory_pointer = MapViewOfFile(shm_fd, FILE_MAP_WRITE, 0, 0, 0);

	if (memory_pointer == NULL) {
		UnmapViewOfFile(memory_pointer);
		lookup_mode = IP2LOCATION_FILE_IO;
		return -1;
	}

	if (is_dababase_loaded == 0) {
		if (IP2Location_load_database_into_memory(file, memory_pointer, buffer.st_size) == -1) {
			UnmapViewOfFile(memory_pointer);
			CloseHandle(shm_fd);
			lookup_mode = IP2LOCATION_FILE_IO;
			return -1;
		}
	}

	return 0;
}
#endif
#endif

// Alias to IP2Location_DB_set_shared_memory()
int32_t IP2Location_set_shared_memory(FILE *file)
{
	return IP2Location_DB_set_shared_memory(file);
}

// Load BIN file into memory
int32_t IP2Location_load_database_into_memory(FILE *file, void *memory, int64_t size)
{
	fseek(file, 0, SEEK_SET);

	if (fread(memory, size, 1, file) != 1) {
		return -1;
	}

	return 0;
}

// Close the corresponding memory, based on the opened option
int32_t IP2Location_DB_close(FILE *file)
{
	struct stat buffer;

	if (lookup_mode == IP2LOCATION_CACHE_MEMORY) {
		if (memory_pointer != NULL) {
			free(memory_pointer);
		}
	} else if (lookup_mode == IP2LOCATION_SHARED_MEMORY) {
		if (memory_pointer != NULL) {
#ifndef	WIN32
			if (fstat(fileno(file), &buffer) == 0) {
				munmap(memory_pointer, buffer.st_size);
			}

			close(shm_fd);
#else
#ifdef WIN32
			UnmapViewOfFile(memory_pointer);
			CloseHandle(shm_fd);
#endif
#endif
		}
	}

	if (file != NULL) {
		fclose(file);
	}

	lookup_mode = IP2LOCATION_FILE_IO;
	return 0;
}


// Alias to IP2Location_DB_close
int32_t IP2Location_close_memory(FILE *file)
{
	return IP2Location_DB_close(file);
}

#ifndef	WIN32
// Remove shared memory object
void IP2Location_DB_del_shm()
{
	shm_unlink(get_shm_name());
}
#else
#ifdef WIN32
void IP2Location_DB_del_shm()
{
}
#endif
#endif

struct in6_addr IP2Location_read128_row(uint8_t* buffer, uint32_t position, uint32_t mem_offset)
{
	int i, j;
	struct in6_addr addr6;
	for (i = 0, j = 15; i < 16; i++, j--)
	{
		addr6.s6_addr[i] = IP2Location_read8_row(buffer, position + j, mem_offset);
	}
	return addr6;
}

struct in6_addr IP2Location_readIPv6Address(FILE *handle, uint32_t position)
{
	int i, j;
	struct in6_addr addr6;

	for (i = 0, j = 15; i < 16; i++, j--) {
		addr6.s6_addr[i] = IP2Location_read8(handle, position + j);
	}

	return addr6;
}

// Alias to IP2Location_readIPv6Address()
struct in6_addr IP2Location_read_ipv6_address(FILE *handle, uint32_t position)
{
	return IP2Location_readIPv6Address(handle, position);
}

uint32_t IP2Location_read32(FILE *handle, uint32_t position)
{
	uint8_t byte1 = 0;
	uint8_t byte2 = 0;
	uint8_t byte3 = 0;
	uint8_t byte4 = 0;
	uint8_t *cache_shm = memory_pointer;
	size_t temp;

	// Read from file
	if (lookup_mode == IP2LOCATION_FILE_IO && handle != NULL) {
		fseek(handle, position - 1, SEEK_SET);
		temp = fread(&byte1, 1, 1, handle);

		if (temp == 0) {
			return 0;
		}

		temp = fread(&byte2, 1, 1, handle);

		if (temp == 0) {
			return 0;
		}

		temp = fread(&byte3, 1, 1, handle);

		if (temp == 0) {
			return 0;
		}

		temp = fread(&byte4, 1, 1, handle);

		if (temp == 0) {
			return 0;
		}
	} else {
		byte1 = cache_shm[position - 1];
		byte2 = cache_shm[position];
		byte3 = cache_shm[position + 1];
		byte4 = cache_shm[position + 2];
	}

	return ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | (byte1));
}

uint32_t IP2Location_read32_row(uint8_t* buffer, uint32_t position, uint32_t mem_offset)
{
    uint8_t* addr;

    if (lookup_mode == IP2LOCATION_FILE_IO) {
        addr = buffer + position;
    } else {
        addr = memory_pointer + mem_offset + position - 1;
    }

    return ((uint32_t)addr[3] << 24) | ((uint32_t)addr[2] << 16) | ((uint32_t)addr[1] << 8) | ((uint32_t)addr[0]);
}

uint8_t IP2Location_read8(FILE *handle, uint32_t position)
{
	uint8_t ret = 0;
	uint8_t *cache_shm = memory_pointer;
	size_t temp;

	if (lookup_mode == IP2LOCATION_FILE_IO && handle != NULL) {
		fseek(handle, position - 1, SEEK_SET);
		temp = fread(&ret, 1, 1, handle);

		if (temp == 0) {
			return 0;
		}
	} else {
		ret = cache_shm[position - 1];
	}

	return ret;
}

uint8_t IP2Location_read8_row(uint8_t* buffer, uint32_t position, uint32_t mem_offset)
{
	uint8_t *cache_shm = memory_pointer;

	if (lookup_mode == IP2LOCATION_FILE_IO) {
		return buffer[position];
	} else {
		return cache_shm[mem_offset + position - 1];
	}
}

char *IP2Location_readStr(FILE *handle, uint32_t position)
{
	uint8_t size = 0;
	char *str = 0;
	uint8_t *cache_shm = memory_pointer;
	size_t temp;

	if (lookup_mode == IP2LOCATION_FILE_IO && handle != NULL) {
		fseek(handle, position, 0);
		temp = fread(&size, 1, 1, handle);

		if (temp == 0) {
			return strdup("");
		}

		str = (char *)malloc(size+1);
		memset(str, 0, size+1);

		temp = fread(str, size, 1, handle);

		if (temp == 0) {
			free(str);
			return strdup("");
		}
	} else {
		size = cache_shm[position];
		str = (char *)malloc(size + 1);
		memset(str, 0, size + 1);
		memcpy((void*) str, (void*)&cache_shm[position + 1], size);
	}

	return str;
}

// Alias to IP2Location_readStr()
// char *IP2Location_read_string(FILE *handle, uint32_t position)
// {
	// return IP2Location_readStr(handle, position);
// }

char *IP2Location_read_string(FILE *handle, uint32_t position)
{
	uint8_t data[255];
	uint8_t size = 0;
	char* str = 0;
	uint8_t *cache_shm = memory_pointer;

	if (lookup_mode == IP2LOCATION_FILE_IO && handle != NULL) {
		fseek(handle, position, 0);
		fread(&data, 255, 1, handle); // max size of string field + 1 byte for length
		size = data[0];
		str = (char *)malloc(size+1);
		memcpy(str, ((uint8_t*)data) + 1, size);
		str[size] = '\0'; // add null terminator
	} else {
		size = cache_shm[position];
		str = (char *)malloc(size + 1);
		memset(str, 0, size + 1);
		memcpy((void*) str, (void*)&cache_shm[position + 1], size);
	}
	return str;
}

float IP2Location_readFloat(FILE *handle, uint32_t position)
{
	float ret = 0.0;
	uint8_t *cache_shm = memory_pointer;
	size_t temp;

#ifdef WORDS_BIGENDIAN
	char *p = (char *) &ret;

	// have to reverse the byte order
	if (lookup_mode == IP2LOCATION_FILE_IO && handle != NULL) {
		fseek(handle, position - 1, 0);

		temp = fread(p + 3, 1, 1, handle);

		if (temp == 0) {
			return 0.0;
		}

		temp = fread(p + 2, 1, 1, handle);

		if (temp == 0) {
			return 0.0;
		}

		temp = fread(p + 1, 1, 1, handle);

		if (temp == 0) {
			return 0.0;
		}

		temp = fread(p, 1, 1, handle);

		if (temp == 0) {
			return 0.0;
		}
	} else {
		*(p+3) = cache_shm[position - 1];
		*(p+2) = cache_shm[position];
		*(p+1) = cache_shm[position + 1];
		*(p) = cache_shm[position + 2];
	}
#else
	if (lookup_mode == IP2LOCATION_FILE_IO && handle != NULL) {
		fseek(handle, position - 1, 0);
		temp = fread(&ret, 4, 1, handle);

		if (temp == 0) {
			return 0.0;
		}
	} else {
		memcpy((void*) &ret, (void*)&cache_shm[position - 1], 4);
	}
#endif
	return ret;
}

// Alias to IP2Location_readFloat()
float IP2Location_read_float(FILE *handle, uint32_t position)
{
	return IP2Location_readFloat(handle, position);
}

float IP2Location_read_float_row(uint8_t* buffer, uint32_t position, uint32_t mem_offset)
{
	float ret = 0.0;
	uint8_t stuff[4];
	uint8_t *cache_shm = memory_pointer;

#ifdef WORDS_BIGENDIAN
	char *p = (char *) &ret;

	// have to reverse the byte order
	if (lookup_mode == IP2LOCATION_FILE_IO) {
		uint8_t temp[4];
		memcpy(&temp, buffer + position, 4);
		stuff[0] = temp[3];
		stuff[1] = temp[2];
		stuff[2] = temp[1];
		stuff[3] = temp[0];
		memcpy(&ret, &stuff, 4);
	} else {
		*(p+3) = cache_shm[mem_offset + position - 1];
		*(p+2) = cache_shm[mem_offset + position];
		*(p+1) = cache_shm[mem_offset + position + 1];
		*(p) = cache_shm[mem_offset + position + 2];
	}
#else
	if (lookup_mode == IP2LOCATION_FILE_IO) {
		memcpy(&stuff, buffer + position, 4);
		memcpy(&ret, &stuff, 4);
	} else {
		memcpy((void*) &ret, (void*)&cache_shm[mem_offset + position - 1], 4);
	}
#endif
	return ret;
}

Cross-licensing?

Heya,

So I'm looking to integrate ip2location support into rgeolocate - the standard R library for IP geolocation. The problem is that, due to other integrated code, it's an apache-licensed project, and ip2location's C lib is lGPL - and the two are incompatible.

Is there any chance you'd be willing to dual-license this project under the Apache 2.0? That way I could integrate it (with appropriate licensing and credit to you).

[8.4.0] failed test

   IP2Loc 8.4.0: test/test-suite.log
=======================================

# TOTAL: 1
# PASS:  0
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0

.. contents:: :depth: 2

FAIL: test-IP2Location
======================

Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file.IP2Location API version: 8.4.0 (80400)
Please install the database in correct path.
FAIL test-IP2Location (exit status: 255)

pvs-studio-analyzer

$ wget https://files.viva64.com/pvs-studio-7.09.41421.64-amd64.deb
$ dpkg -i pvs-studio-7.09.41421.64-amd64.deb
$ pvs-studio-analyzer credentials (email) (license) # free opensource https://www.viva64.com/en/b/0600/

$ cd IP2Location-C-Library
$ make clean
$ bear make
$ ls compile_commands.json

#     -a [MODE], --analysis-mode [MODE]
#        MODE defines the type of warnings:
#        1 - diagnostics, allowing to detect specific errors, related to the development of 64-bit applications and migrating the code from a 32-bit platform to a 64-bit one.
#        2 - reserved;
#        4 - General Analysis diagnostics. This is the main set of diagnostic rules
#        8 - Diagnostics of micro-optimization. These are tips concerning the improvement of efficiency and safety of the code.
#        16 - highly specialized diagnostics, developed by user requests. By default, this set of diagnostics is disabled.
#        32 - a set of diagnostics, developed according to the MISRA standard (Motor Industry Software Reliability Association). This set of diagnostics is disabled by default.
$ pvs-studio-analyzer analyze -a "$((1|2|4|8|16|32))" -o ip2loc.proj -j4
$ plog-converter -a 'GA;OP;64;CS;MISRA' -t errorfile -o ip2loc.log ip2loc.proj

$ cat ip2loc.log
www.viva64.com/en/w:1:1: error: Help: The documentation for all analyzer warnings is available here: https://www.viva64.com/en/w/.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.h:26:1: note: V2514 Unions should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.h:107:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:126:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:127:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:128:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:129:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:130:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:133:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:134:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:135:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:136:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:137:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:138:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:139:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:140:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:141:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:142:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:143:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:145:1: note: V122 Memsize type is used in the struct/class.
IP2Location-C-Library/libIP2Location/IP2Location.h:177:1: note: V126 Be advised that the size of the type 'long' varies between LLP64/LP64 data models.
IP2Location-C-Library/test/test-IP2Location.c:21:1: warning: V2532 String literal should not be assigned to object unless it has type of pointer to const-qualified char.
IP2Location-C-Library/test/test-IP2Location.c:40:1: note: V575 The potential null pointer is passed into 'fscanf' function. Inspect the first argument.
IP2Location-C-Library/test/test-IP2Location.c:40:1: warning: V576 Incorrect format. Consider checking the third actual argument of the 'fscanf' function. It's dangerous to use string specifier without width specification. Buffer overflow is possible.
IP2Location-C-Library/test/test-IP2Location.c:41:1: warning: V576 Incorrect format. Consider checking the third actual argument of the 'fscanf' function. It's dangerous to use string specifier without width specification. Buffer overflow is possible.
IP2Location-C-Library/test/test-IP2Location.c:76:1: warning: V2532 String literal should not be assigned to object unless it has type of pointer to const-qualified char.
IP2Location-C-Library/test/test-IP2Location.c:91:1: warning: V576 Incorrect format. Consider checking the third actual argument of the 'fscanf' function. It's dangerous to use string specifier without width specification. Buffer overflow is possible.
IP2Location-C-Library/test/test-IP2Location.c:92:1: warning: V576 Incorrect format. Consider checking the third actual argument of the 'fscanf' function. It's dangerous to use string specifier without width specification. Buffer overflow is possible.
IP2Location-C-Library/test/test-IP2Location.c:11:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:60:1: warning: V2511 The function with the 'malloc' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:60:1: note: V2572 The value of the 'statbuf.st_size + 1' expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:60:1: note: V2561 The result of an assignment expression should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:68:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:50:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:80:1: warning: V2523 All integer constants of unsigned type should have 'u' or 'U' suffix.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:80:1: error: V204 Explicit conversion from 32-bit integer type to pointer type: (void *) 4194500608
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:80:1: note: V566 The integer constant is converted to pointer. Possibly an error or a bad coding style: (void *) 4194500608
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:84:1: warning: V2501 Octal constant '02' should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:84:1: warning: V2501 Octal constant '0100' should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:84:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '02', right - '0100'
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:84:1: warning: V2501 Octal constant '0200' should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:84:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '02 | 0100', right - '0200'
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:84:1: warning: V2501 Octal constant '0777' should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:84:1: note: V2561 The result of an assignment expression should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:88:1: warning: V2501 Octal constant '02' should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:88:1: warning: V2501 Octal constant '0777' should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:88:1: note: V2561 The result of an assignment expression should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:88:1: warning: V2516 The 'if' ... 'else if' construct should be terminated with an 'else' statement.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:96:1: warning: V2507 The body of the 'if' statement should be enclosed in braces.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:102:1: note: V2572 The value of the 'statbuf.st_size + 1' expression should not be converted to the narrower essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:110:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '0x1', right - '0x2'
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:114:1: warning: V2507 The body of the 'if' statement should be enclosed in braces.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:76:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:195:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:195:1: warning: V2507 The body of the 'if' statement should be enclosed in braces.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:192:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:208:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:207:1: note: V809 Verifying that a pointer value is not NULL is not required. The 'if (cache_shm_ptr != NULL)' check can be removed.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:207:1: warning: V2507 The body of the 'if' statement should be enclosed in braces.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:210:1: warning: V2516 The 'if' ... 'else if' construct should be terminated with an 'else' statement.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:229:1: warning: V2507 The body of the 'if' statement should be enclosed in braces.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:215:1: error: V595 The 'filehandle' pointer was utilized before it was verified against nullptr. Check lines: 215, 229.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:253:1: note: V2528 The comma operator should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:255:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:266:1: note: V2571 Pointer to void should not be converted to a pointer to object. Consider inspecting the expression: '* cache_shm = cache_shm_ptr'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:272:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:272:1: warning: V106 Implicit type conversion second argument 'position - 1' of function 'fseek' to memsize type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:274:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:276:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:278:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:280:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:284:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:284:1: warning: V108 Incorrect index type: cache_shm[not a memsize-type]. Use memsize type instead.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:285:1: warning: V108 Incorrect index type: cache_shm[not a memsize-type]. Use memsize type instead.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:286:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:286:1: warning: V108 Incorrect index type: cache_shm[not a memsize-type]. Use memsize type instead.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:287:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:287:1: warning: V108 Incorrect index type: cache_shm[not a memsize-type]. Use memsize type instead.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:289:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '(byte4 << 24)', right - '(byte3 << 16)'
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:289:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '(byte4 << 24) | (byte3 << 16)', right - '(byte2 << 8)'
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:289:1: warning: V2568 Both operands of the '|' operator should have the same essential type. The current types are: 'signed' and 'unsigned'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:289:1: warning: V2544 Operands of the '|' operator should have appropriate essential types.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:260:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:295:1: note: V2571 Pointer to void should not be converted to a pointer to object. Consider inspecting the expression: '* cache_shm = cache_shm_ptr'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:300:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:300:1: warning: V106 Implicit type conversion second argument 'position - 1' of function 'fseek' to memsize type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:302:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:306:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:306:1: warning: V108 Incorrect index type: cache_shm[not a memsize-type]. Use memsize type instead.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:292:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:315:1: note: V2571 Pointer to void should not be converted to a pointer to object. Consider inspecting the expression: '* cache_shm = cache_shm_ptr'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:320:1: warning: V106 Implicit type conversion second argument 'position' of function 'fseek' to memsize type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:322:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:322:1: warning: V2532 String literal should not be assigned to object unless it has type of pointer to const-qualified char.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:323:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:323:1: warning: V2511 The function with the 'malloc' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:323:1: note: V2572 The value of the 'size + 1' expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:324:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:324:1: warning: V575 The potential null pointer is passed into 'memset' function. Inspect the first argument. Check lines: 324, 323.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:326:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:326:1: error: V773 The function was exited without releasing the 'str' pointer. A memory leak is possible.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:326:1: warning: V2532 String literal should not be assigned to object unless it has type of pointer to const-qualified char.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:330:1: warning: V108 Incorrect index type: cache_shm[not a memsize-type]. Use memsize type instead.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:331:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:331:1: warning: V2511 The function with the 'malloc' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:331:1: note: V2572 The value of the 'size + 1' expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:332:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:333:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:333:1: warning: V108 Incorrect index type: cache_shm[not a memsize-type]. Use memsize type instead.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:311:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:340:1: note: V2572 The value of the '0.0' expression should not be converted to the narrower essential 'floating' type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:341:1: note: V2571 Pointer to void should not be converted to a pointer to object. Consider inspecting the expression: '* cache_shm = cache_shm_ptr'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:370:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:370:1: warning: V106 Implicit type conversion second argument 'position - 1' of function 'fseek' to memsize type.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:371:1: warning: V112 Dangerous magic number 4 used: ...fread(&ret, 4, 1, handle);.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:372:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:376:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:376:1: warning: V108 Incorrect index type: cache_shm[not a memsize-type]. Use memsize type instead.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:376:1: warning: V112 Dangerous magic number 4 used: ...tion - 1 ], 4);.
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:338:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Location.c:76:1: note: V2561 The result of an assignment expression should not be used. Consider inspecting the expression: 'f = fopen(db, "rb")'.
IP2Location-C-Library/libIP2Location/IP2Location.c:82:1: warning: V2511 The function with the 'calloc' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:83:1: warning: V522 There might be dereferencing of a potential null pointer 'loc'. Check lines: 83, 82.
IP2Location-C-Library/libIP2Location/IP2Location.c:71:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Location.c:92:1: warning: V2507 The body of the 'if' statement should be enclosed in braces.
IP2Location-C-Library/libIP2Location/IP2Location.c:96:1: warning: V2507 The body of the 'if' statement should be enclosed in braces.
IP2Location-C-Library/libIP2Location/IP2Location.c:112:1: warning: V2507 The body of the 'else' branch should be enclosed in braces.
IP2Location-C-Library/libIP2Location/IP2Location.c:90:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Location.c:123:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:141:1: warning: V112 Dangerous magic number 4 used: ...filehandle, 4);.
IP2Location-C-Library/libIP2Location/IP2Location.c:170:1: warning: V2516 The 'if' ... 'else if' construct should be terminated with an 'else' statement.
IP2Location-C-Library/libIP2Location/IP2Location.c:160:1: note: V2009 Consider rendering the 'addr1', 'addr2' pointers as pointers to const. 
IP2Location-C-Library/libIP2Location/IP2Location.c:163:1: note: V2530 The loop should be terminated with no more than one 'break' or 'goto' statement.
IP2Location-C-Library/libIP2Location/IP2Location.c:188:1: warning: V2567 The cast should not remove 'const' qualification from the type that is pointed to by a pointer.
IP2Location-C-Library/libIP2Location/IP2Location.c:190:1: warning: V112 Dangerous magic number 4 used: ...ipversion = 4;.
IP2Location-C-Library/libIP2Location/IP2Location.c:190:1: warning: V2568 Both operands of the '=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:191:1: warning: V2567 The cast should not remove 'const' qualification from the type that is pointed to by a pointer.
IP2Location-C-Library/libIP2Location/IP2Location.c:193:1: warning: V2567 The cast should not remove 'const' qualification from the type that is pointed to by a pointer.
IP2Location-C-Library/libIP2Location/IP2Location.c:197:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:198:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:199:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:200:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:203:1: warning: V112 Dangerous magic number 4 used: ...ipversion = 4;.
IP2Location-C-Library/libIP2Location/IP2Location.c:203:1: warning: V2568 Both operands of the '=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:204:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'signed' and 'unsigned'.
IP2Location-C-Library/libIP2Location/IP2Location.c:204:1: note: V2572 Value of the expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:204:1: warning: V2568 Both operands of the '=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:209:1: warning: V2568 Both operands of the '=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:214:1: note: V2572 The value of the '-1' expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:214:1: warning: V2568 Both operands of the '=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '0x00001', right - '0x00002'
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '0x00001 | 0x00002', right - '0x00004'
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '0x00001 | 0x00002 | 0x00004', right - '0x00008'
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The left and right operands of the '|' operator should not have essential 'signed' and 'signed' types respectively. Consider inspecting operands: left - '0x00001 | 0x00002 | 0x00004 | 0x00008', right - '0x00010'
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x00020' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x00040' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x00080' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x00100' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x00200' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x00400' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x00800' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x01000' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x02000' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x04000' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x08000' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x10000' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x20000' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x40000' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:343:1: warning: V2544 The right operand '0x80000' of the '|' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:355:1: warning: V2568 Both operands of the '=' operator should have the same essential type. The current types are: 'floating' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:356:1: warning: V2568 Both operands of the '=' operator should have the same essential type. The current types are: 'floating' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:368:1: warning: V2568 Both operands of the '=' operator should have the same essential type. The current types are: 'floating' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:381:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:381:1: warning: V2544 The right operand '0x00001' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:381:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:381:1: warning: V2544 The left operand '(mode & 0x00001)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:385:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (COUNTRY_...
IP2Location-C-Library/libIP2Location/IP2Location.c:385:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:385:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:396:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:396:1: warning: V2544 The right operand '0x00002' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:396:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:396:1: warning: V2544 The left operand '(mode & 0x00002)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:400:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (COUNTRY_...
IP2Location-C-Library/libIP2Location/IP2Location.c:400:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:400:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:411:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:411:1: warning: V2544 The right operand '0x00004' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:411:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:411:1: warning: V2544 The left operand '(mode & 0x00004)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:415:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (REGION_P...
IP2Location-C-Library/libIP2Location/IP2Location.c:415:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:415:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:426:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:426:1: warning: V2544 The right operand '0x00008' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:426:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:426:1: warning: V2544 The left operand '(mode & 0x00008)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:430:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (CITY_POS...
IP2Location-C-Library/libIP2Location/IP2Location.c:430:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:430:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:441:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:441:1: warning: V2544 The right operand '0x00010' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:441:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:441:1: warning: V2544 The left operand '(mode & 0x00010)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:445:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (ISP_POSI...
IP2Location-C-Library/libIP2Location/IP2Location.c:445:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:445:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:456:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:456:1: warning: V2544 The right operand '0x00020' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:456:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:456:1: warning: V2544 The left operand '(mode & 0x00020)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:458:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (LATITUDE...
IP2Location-C-Library/libIP2Location/IP2Location.c:458:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:458:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:462:1: note: V2572 The value of the '0.0' expression should not be converted to the narrower essential 'floating' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:465:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:465:1: warning: V2544 The right operand '0x00040' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:465:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:465:1: warning: V2544 The left operand '(mode & 0x00040)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:467:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (LONGITUD...
IP2Location-C-Library/libIP2Location/IP2Location.c:467:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:467:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:471:1: note: V2572 The value of the '0.0' expression should not be converted to the narrower essential 'floating' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:474:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:474:1: warning: V2544 The right operand '0x00080' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:474:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:474:1: warning: V2544 The left operand '(mode & 0x00080)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:478:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (DOMAIN_P...
IP2Location-C-Library/libIP2Location/IP2Location.c:478:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:478:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:489:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:489:1: warning: V2544 The right operand '0x00100' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:489:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:489:1: warning: V2544 The left operand '(mode & 0x00100)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:493:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (ZIPCODE_...
IP2Location-C-Library/libIP2Location/IP2Location.c:493:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:493:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:504:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:504:1: warning: V2544 The right operand '0x00200' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:504:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:504:1: warning: V2544 The left operand '(mode & 0x00200)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:508:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (TIMEZONE...
IP2Location-C-Library/libIP2Location/IP2Location.c:508:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:508:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:519:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:519:1: warning: V2544 The right operand '0x00400' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:519:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:519:1: warning: V2544 The left operand '(mode & 0x00400)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:523:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (NETSPEED...
IP2Location-C-Library/libIP2Location/IP2Location.c:523:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:523:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:534:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:534:1: warning: V2544 The right operand '0x00800' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:534:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:534:1: warning: V2544 The left operand '(mode & 0x00800)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:538:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (IDDCODE_...
IP2Location-C-Library/libIP2Location/IP2Location.c:538:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:538:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:549:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:549:1: warning: V2544 The right operand '0x01000' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:549:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:549:1: warning: V2544 The left operand '(mode & 0x01000)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:553:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (AREACODE...
IP2Location-C-Library/libIP2Location/IP2Location.c:553:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:553:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:564:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:564:1: warning: V2544 The right operand '0x02000' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:564:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:564:1: warning: V2544 The left operand '(mode & 0x02000)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:568:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (WEATHERS...
IP2Location-C-Library/libIP2Location/IP2Location.c:568:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:568:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:579:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:579:1: warning: V2544 The right operand '0x04000' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:579:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:579:1: warning: V2544 The left operand '(mode & 0x04000)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:583:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (WEATHERS...
IP2Location-C-Library/libIP2Location/IP2Location.c:583:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:583:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:594:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:594:1: warning: V2544 The right operand '0x08000' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:594:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:594:1: warning: V2544 The left operand '(mode & 0x08000)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:598:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (MCC_POSI...
IP2Location-C-Library/libIP2Location/IP2Location.c:598:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:598:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:609:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:609:1: warning: V2544 The right operand '0x10000' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:609:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:609:1: warning: V2544 The left operand '(mode & 0x10000)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:613:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (MNC_POSI...
IP2Location-C-Library/libIP2Location/IP2Location.c:613:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:613:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:624:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:624:1: warning: V2544 The right operand '0x20000' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:624:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:624:1: warning: V2544 The left operand '(mode & 0x20000)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:628:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (MOBILEBR...
IP2Location-C-Library/libIP2Location/IP2Location.c:628:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:628:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:639:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:639:1: warning: V2544 The right operand '0x40000' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:639:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:639:1: warning: V2544 The left operand '(mode & 0x40000)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:641:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (ELEVATIO...
IP2Location-C-Library/libIP2Location/IP2Location.c:641:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:641:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:642:1: warning: V2508 The function with the 'atof' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:642:1: note: V2572 The value of the 'atof(mem)' expression should not be converted to the narrower essential 'floating' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:643:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:647:1: note: V2572 The value of the '0.0' expression should not be converted to the narrower essential 'floating' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:650:1: warning: V2568 Both operands of the '&' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:650:1: warning: V2544 The right operand '0x80000' of the '&' operator should not have the essential 'signed' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:650:1: warning: V2568 Both operands of the '!=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:650:1: warning: V2544 The left operand '(mode & 0x80000)' of the '&&' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:654:1: warning: V112 Dangerous magic number 4 used: ..., rowaddr + 4 * (USAGETYP...
IP2Location-C-Library/libIP2Location/IP2Location.c:654:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:654:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:375:1: error: V2008 Cyclomatic complexity:    75. Consider refactoring the 'IP2Location_read_record' function.
IP2Location-C-Library/libIP2Location/IP2Location.c:685:1: warning: V2544 The 'high' operand of the '!' operator should not have the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:685:1: warning: V2570 Operands of the '!' operator should have bool essential type.
IP2Location-C-Library/libIP2Location/IP2Location.c:690:1: warning: V2568 Both operands of the '>' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:693:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:693:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'signed' and 'unsigned'.
IP2Location-C-Library/libIP2Location/IP2Location.c:693:1: note: V2572 Value of the expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:697:1: warning: V112 Dangerous magic number 4 used: ...indexpos + 4);.
IP2Location-C-Library/libIP2Location/IP2Location.c:697:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:704:1: warning: V112 Dangerous magic number 4 used: ...(dbcolumn * 4 + 12));.
IP2Location-C-Library/libIP2Location/IP2Location.c:704:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:704:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:705:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:705:1: warning: V112 Dangerous magic number 4 used: ...(dbcolumn * 4 + 12));.
IP2Location-C-Library/libIP2Location/IP2Location.c:705:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:709:1: warning: V112 Dangerous magic number 4 used: ...(dbcolumn * 4 + 12) + 12,...
IP2Location-C-Library/libIP2Location/IP2Location.c:709:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:709:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:715:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:719:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:668:1: warning: V813 Decreased performance. The 'parsed_ipv' argument should probably be rendered as a constant pointer.
IP2Location-C-Library/libIP2Location/IP2Location.c:668:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Location.c:668:1: note: V2537 Functions should not have unused parameters. Consider inspecting the parameter: 'ipstring'.
IP2Location-C-Library/libIP2Location/IP2Location.c:745:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:748:1: warning: V2568 Both operands of the '>' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:755:1: warning: V112 Dangerous magic number 4 used: ...indexpos + 4);.
IP2Location-C-Library/libIP2Location/IP2Location.c:755:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:761:1: warning: V112 Dangerous magic number 4 used: ...dbcolumn * 4);.
IP2Location-C-Library/libIP2Location/IP2Location.c:761:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:762:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:762:1: warning: V112 Dangerous magic number 4 used: ...dbcolumn * 4);.
IP2Location-C-Library/libIP2Location/IP2Location.c:762:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:766:1: warning: V112 Dangerous magic number 4 used: ...dbcolumn * 4), mode);.
IP2Location-C-Library/libIP2Location/IP2Location.c:766:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:772:1: warning: V2568 Both operands of the '-' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:776:1: warning: V2568 Both operands of the '+' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:727:1: warning: V813 Decreased performance. The 'parsed_ipv' argument should probably be rendered as a constant pointer.
IP2Location-C-Library/libIP2Location/IP2Location.c:727:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Location.c:727:1: note: V2537 Functions should not have unused parameters. Consider inspecting the parameter: 'ipstring'.
IP2Location-C-Library/libIP2Location/IP2Location.c:787:1: warning: V112 Dangerous magic number 4 used: ...pversion == 4).
IP2Location-C-Library/libIP2Location/IP2Location.c:787:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:792:1: warning: V2568 Both operands of the '==' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:784:1: note: V2506 A function should have a single point of exit at the end.
IP2Location-C-Library/libIP2Location/IP2Location.c:806:1: warning: V2511 The function with the 'calloc' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:817:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:818:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:819:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:820:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:821:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:822:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:823:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:824:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:825:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:826:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:827:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:828:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:829:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:830:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:831:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:832:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:833:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:834:1: warning: V2511 The function with the 'free' name should not be used.
IP2Location-C-Library/libIP2Location/IP2Location.c:811:1: note: V2506 The 'return' statement should be the last statement of a function.
IP2Location-C-Library/libIP2Location/IP2Location.c:841:1: note: V206 Explicit conversion from 'unsigned int *' to 'unsigned char *'.
IP2Location-C-Library/libIP2Location/IP2Location.c:847:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:847:1: note: V2572 The value of the '(uint8_t)(ptr[2]) * 256' expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:847:1: warning: V2568 Both operands of the '+=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:848:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:848:1: note: V2572 The value of the '(uint8_t)(ptr[1]) * 256 * 256' expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:848:1: warning: V2568 Both operands of the '+=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:849:1: warning: V2568 Both operands of the '*' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:849:1: note: V2572 The value of the '(uint8_t)(ptr[0]) * 256 * 256 * 256' expression should not be converted from the essential 'signed' type to the essential 'unsigned' type.
IP2Location-C-Library/libIP2Location/IP2Location.c:849:1: warning: V2568 Both operands of the '+=' operator should have the same essential type. The current types are: 'unsigned' and 'signed'.
IP2Location-C-Library/libIP2Location/IP2Location.c:840:1: error: V595 The 'ipstring' pointer was utilized before it was verified against nullptr. Check lines: 840, 844.
IP2Location-C-Library/libIP2Location/IP2Location.c:838:1: note: V2009 Consider rendering the 'ipstring' pointer as a pointer to const.
IP2Location-C-Library/libIP2Location/IP2Location.c:856:1: note: V2009 Consider rendering the 'ipaddr' pointer as a pointer to const.
IP2Location-C-Library/libIP2Location/IP2Location.c:863:1: note: V2009 Consider rendering the 'ipaddr' pointer as a pointer to const.
IP2Location-C-Library/libIP2Location/IP2Location.c:870:1: note: V126 Be advised that the size of the type 'long' varies between LLP64/LP64 data models.
IP2Location-C-Library/libIP2Location/IP2Location.c:886:1: warning: V2532 String literal should not be assigned to object unless it has type of pointer to const-qualified char.
IP2Location-C-Library/libIP2Location/IP2Location.c:27:1: warning: V2573 Identifiers that start with '__' or '_[A-Z]' are reserved. Consider inspecting the '_STR2' identifier.
IP2Location-C-Library/libIP2Location/IP2Location.c:28:1: warning: V2573 Identifiers that start with '__' or '_[A-Z]' are reserved. Consider inspecting the '_STR' identifier.

"make check" for IPv6 is broken

looks like the IPv6 database created by the builtin "ip-country.pl" is no longer proper working, initialy "make check" segfaults, because NULL was returned on "get_all" -> imho this need some rework to support current status, which means one BIN file containing IPv4 and IPv6.

C-99 required in IP2Loc_DBInterface.c

This snippet at the end of IP2Location_readFloat() needs a C-99 compiler:

  {
        fseek(handle, position-1, 0);
        size_t temp = fread(&ret, 4, 1, handle);
  }

size_t could easily be dropped as it is declared at the top.

Example datasets the wrong way around?

The trial, IPv6 version of the 24-field database here works with an IPv4 address I tried, but produces 'unallocated' or 'invalid' for every IPv6 I throw at it. Are the files the wrong way around, or...?

cppcheck

$ sh ./bootstrap; autoreconf -fi; ./configure --disable-static
$ make clean
$ bear make
$ cat compile_commands.json
$ cppcheck --project=compile_commands.json --enable=warning,performance,portability -f -j4 libIP2Location 2> err.txt
$ cat err.txt
libIP2Location/IP2Loc_DBInterface.c:326:19: error: Memory leak: str [memleak]
 if (temp == 0) { return ""; };
                  ^
IP2Location-C-Library/test/test-IP2Location.c:40:9: warning: fscanf() without field width limits can crash with huge input data. [invalidscanf]
 while (fscanf(f, "%s", ipAddress) != EOF) {
        ^
IP2Location-C-Library/test/test-IP2Location.c:41:7: warning: fscanf() without field width limits can crash with huge input data. [invalidscanf]
  if (fscanf(f, "%s", expectedCountry) == EOF) {
      ^
IP2Location-C-Library/test/test-IP2Location.c:91:9: warning: fscanf() without field width limits can crash with huge input data. [invalidscanf]
 while (fscanf(f, "%s", ipAddress) != EOF) {
        ^
IP2Location-C-Library/test/test-IP2Location.c:92:7: warning: fscanf() without field width limits can crash with huge input data. [invalidscanf]
  if (fscanf(f, "%s", expectedCountry) == EOF) {
      ^
libIP2Location/IP2Location.c:846:27: error: The address of local variable 'ip' is accessed at non-zero index. [objectIndex]
        a =  (uint8_t)(ptr[3]);
                          ^
libIP2Location/IP2Location.c:841:32: note: Address of variable taken here.
    uint8_t *ptr = (uint8_t *) &ip;
                               ^
libIP2Location/IP2Location.c:846:27: note: The address of local variable 'ip' is accessed at non-zero index.
        a =  (uint8_t)(ptr[3]);
                          ^
libIP2Location/IP2Location.c:847:27: error: The address of local variable 'ip' is accessed at non-zero index. [objectIndex]
        a += (uint8_t)(ptr[2]) * 256;
                          ^
libIP2Location/IP2Location.c:841:32: note: Address of variable taken here.
    uint8_t *ptr = (uint8_t *) &ip;
                               ^
libIP2Location/IP2Location.c:847:27: note: The address of local variable 'ip' is accessed at non-zero index.
        a += (uint8_t)(ptr[2]) * 256;
                          ^
libIP2Location/IP2Location.c:848:27: error: The address of local variable 'ip' is accessed at non-zero index. [objectIndex]
        a += (uint8_t)(ptr[1]) * 256 * 256;
                          ^
libIP2Location/IP2Location.c:841:32: note: Address of variable taken here.
    uint8_t *ptr = (uint8_t *) &ip;
                               ^
libIP2Location/IP2Location.c:848:27: note: The address of local variable 'ip' is accessed at non-zero index.
        a += (uint8_t)(ptr[1]) * 256 * 256;
                          ^
IP2Location-C-Library/libIP2Location/IP2Loc_DBInterface.c:326:19: error: Memory leak: str [memleak]
 if (temp == 0) { return ""; };
                  ^
IP2Location-C-Library/libIP2Location/IP2Location.c:846:27: error: The address of local variable 'ip' is accessed at non-zero index. [objectIndex]
        a =  (uint8_t)(ptr[3]);
                          ^
IP2Location-C-Library/libIP2Location/IP2Location.c:841:32: note: Address of variable taken here.
    uint8_t *ptr = (uint8_t *) &ip;
                               ^
IP2Location-C-Library/libIP2Location/IP2Location.c:846:27: note: The address of local variable 'ip' is accessed at non-zero index.
        a =  (uint8_t)(ptr[3]);
                          ^
IP2Location-C-Library/libIP2Location/IP2Location.c:847:27: error: The address of local variable 'ip' is accessed at non-zero index. [objectIndex]
        a += (uint8_t)(ptr[2]) * 256;
                          ^
IP2Location-C-Library/libIP2Location/IP2Location.c:841:32: note: Address of variable taken here.
    uint8_t *ptr = (uint8_t *) &ip;
                               ^
IP2Location-C-Library/libIP2Location/IP2Location.c:847:27: note: The address of local variable 'ip' is accessed at non-zero index.
        a += (uint8_t)(ptr[2]) * 256;
                          ^
IP2Location-C-Library/libIP2Location/IP2Location.c:848:27: error: The address of local variable 'ip' is accessed at non-zero index. [objectIndex]
        a += (uint8_t)(ptr[1]) * 256 * 256;
                          ^
IP2Location-C-Library/libIP2Location/IP2Location.c:841:32: note: Address of variable taken here.
    uint8_t *ptr = (uint8_t *) &ip;
                               ^
IP2Location-C-Library/libIP2Location/IP2Location.c:848:27: note: The address of local variable 'ip' is accessed at non-zero index.
        a += (uint8_t)(ptr[1]) * 256 * 256;
                          ^
^

UNICODE support

This is more like a suggestion, but you could add UNICODE support as well? So people with UNICODE apps do not need to convert from ASCII...

You could also add lookup based on IN_ADDR instead of formatted string.

Again, these are just suggestions but they would be very nice to have.

Create 8.0.5 release

The changelog states you are at version 8.0.5 but the releases page only shows 8.0.4.

I am trying to use the provided specfile to build an RPM package but I'm having to manually download / rename the master.zip in order for it to work.

IP2Location-Lite-data RPM and "ip2locationlookup"

this is related to #27

would it make sense to request similar to GeoIP-GeoLite-data an independent IP2Location-Lite-data RPM (dedicated package) -> should get regular updates

or should I create only a subpackage in the IP2Location RPM named IP2Location-data-sample which get only update from release to release (if ever) for initial testing.

Which leads me also to the request of "ip2locationlookup" (similar to geoiplookup), which uses the library and default or provided BIN files to check whether all is working fine.

[8.4.0] failed test

8.4.0 Still failed tests.
ip-country.pl set 29,30 byte to 0 therefore this test fail

if (handler->product_code == 1) {
} else {
	if (handler->database_year <= 20 && handler->product_code == 0) {
	} else {
		printf(INVALID_BIN_DATABASE);
		return NULL;
	}
}

IP2Loc 8.4.0: test/test-suite.log
=======================================

# TOTAL: 1
# PASS: 0
# SKIP: 0
# XFAIL: 0
# FAIL: 1
# XPASS: 0
# ERROR: 0

.. contents:: :depth: 2

FAIL: test-IP2Location
======================

IP2Location library error in opening database ../data/IP-COUNTRY.BIN.
IP2Location API version: 8.4.0 (80400)
Please install the database in correct path.
FAIL test-IP2Location (exit status: 255)

Buffer Overflow in IP2Location.c

"The format string argument to sscanf() at IP2Location.c line 876 does not properly limit the amount of data the function can write, which allows the program to write outside the bounds of allocated memory. This behavior could corrupt data, crash the program, or lead to the execution of malicious code"

Possible to have this fixed?

876 sscanf(iter->data, "%x",(unsigned int *)&value );

Empty records return garbled strings

The library may return gabled strings if the record it reads is empty. The easiest way to reproduce is by using the IP-COUNTRY-SAMPLE.BIN sample database from https://www.ip2location.com/development-libraries to query any record above 100.x.x.x.

When it finds the record, it looks for a pointer to a string in the file for the country, but it points to 0. It then just reads some stuff from the beginning of the file and returns it as the country code and country name.

Off course this means that the provided binary file is incorrect (it should probably point to the string -), but it also points out some major flaws in the structure of the database. The fact that it can just point to any position in the file scares me and seems very error prone to me.

Inconsistencies and error using ASN database

Hi,

I found some issues in my attempt of using the IP2Location™ LITE IP-ASN Database. Please see below:

  • It is impossible to download the BIN format; the website always gives you the CSV format
  • It is impossible to open and load 2 databases at the same time (for example IP2LOCATION-LITE-DB3.BIN and IP2LOCATION-LITE-ASN.BIN); now I`m not sure if this is due to the fact that I converted the ASN CSV to BIN format using your script...?
  • It is unclear which record is the ASN; the ASN CSV contains the number + name, yet there is no function to retrieve it. There is IP2Location_get_isp(), however this returns what exactly? (cannot test since I cannot open the ASN DB)

Please try to answer my questions/issues.

Thanks

SIGBUS error on mmap

Hello!

I encountered an issue when using IP2Location with IP2LOCATION_SHARED_MEMORY access type, and reloading the database regularly, within the same running process.

So, the process simply calls IP2Location_DB_close() and IP2Location_delete_shm(), then IP2Location_open() and IP2Location_open_mem(IP2LOCATION_SHARED_MEMORY) again.

Sometimes, the process crashes with SIGBUS when fread()ing the data into the mmap()ed shared memory segment. This is caused by the process eventually running out of memory because of an issue in the IP2Location_DB_close() function: the file handle is fclose()d before we call fstat() on it, so munmap() is called with the wrong size (so, not all memory is freed):

int32_t IP2Location_DB_close(FILE *filehandle)
{
    struct stat statbuf;
    if ( filehandle != NULL )
        fclose(filehandle);            <---- filehandle closed here
    if ( DB_access_type == IP2LOCATION_CACHE_MEMORY )
    {
        if( cache_shm_ptr != NULL )
            free(cache_shm_ptr);
    }
    else if ( DB_access_type == IP2LOCATION_SHARED_MEMORY )
    {
        if( cache_shm_ptr != NULL )
        {
#ifndef	WIN32
            if(fstat(fileno(filehandle), &statbuf) == 0)      <---- filehandle used here
            {
                munmap(cache_shm_ptr, statbuf.st_size);
            }
            close(shm_fd);
#else
#ifdef WIN32
            UnmapViewOfFile(cache_shm_ptr);
            CloseHandle(shm_fd);
#endif
#endif
        }
    }
    DB_access_type = IP2LOCATION_FILE_IO;
    return 0;
}

The fix is to put the following block:

    if ( filehandle != NULL )
        fclose(filehandle);

at the end of the IP2Location_DB_close() function.

new fields in 8.4.0 "address_type" "category" - any example available?

Can one provide a valid output example, current sample database 25 only contains "DEMO":

$ ./ip2location -d IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.SAMPLE.BIN -p 1.2.3.4 
"ip","country_code","country_name","region_name","city_name","isp","latitude","longitude","domain","zip_code","time_zone","net_speed","idd_code","area_code","weather_station_code","weather_station_name","mcc","mnc","mobile_brand","elevation","usage_type","address_type","category"
"1.2.3.4","US","United States of America","DEMO","DEMO","DEMO","0.000000","0.000000","DEMO","DEMO","DEMO","DEMO","DEMO","DEMO","DEMO","DEMO","DEMO","DEMO","DEMO","0.000000","DEMO","DEMO","DEMO"

$ ./ip2location -d IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.SAMPLE.BIN -p 1.2.3.4 -b
BIN version 2021-5-26

also from code it is not visible what values will be exposed here by database for particular IP addresses.

Read functions revert to reading from shm when file pointer is NULL

I noticed something weird with the read functions where would be read from shm, even though IP2LOCATION_FILE_IO is configured as the access type when the file pointer is NULL.

Consider this snipper from the IP2Location_read32 function in IP2Loc_DBInterface.c:

if (DB_access_type == IP2LOCATION_FILE_IO && handle != NULL)
{
    // reads from file
}
else
{
    // reads from shm
}

I think the handle != NULL check should be done one level deeper. However, I'm not sure what the function should return in that case.

The following code would obviously result in a segfault:

auto db = IP2Location_open("data/IP-COUNTRY-SAMPLE.BIN");
db->filehandle = NULL;

auto record = IP2Location_get_all(db, "127.0.0.1");

Thread safety and lookup speed?

Hi there,

I have a couple of questions which might save me some time because I am really time constrained:

  • Is this library thread safe?
  • Do I need to create a vector/map cache or has this been already optimized for fast and efficient lookup?

Thank you!

8.6.0: IPv6 DB-26 sample database broken?

while DB-25 sample database lookup ok with 8.6.0

ip2location --data-file IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.SAMPLE.BIN --ip 2a04::1
"ip","country_code","country_name","region_name","city_name","isp","latitude","longitude","domain","zip_code","time_zone","net_speed","idd_code","area_code","weather_station_code","weather_station_name","mcc","mnc","mobile_brand","elevation","usage_type","address_type","category","district","as_number","as_name"
"2a04::1","DE","Germany","Rheinland-Pfalz","Winnen","Winnen Gesellschaft Fur Elektro- und Kommunikationstechnik mbH","50.583328","8.016670","winnen.de","56459","+02:00","DSL","49","02664","GMXX0224","Rennerod","-","-","-","469.000000","ISP","U","IAB19-18","N/A","N/A","N/A"

DB-26 has issues on IPv6:

ip2location --data-file IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN.SAMPLE.BIN --ip 2a04::1
"ip","country_code","country_name","region_name","city_name","isp","latitude","longitude","domain","zip_code","time_zone","net_speed","idd_code","area_code","weather_station_code","weather_station_name","mcc","mnc","mobile_brand","elevation","usage_type","address_type","category","district","as_number","as_name"
"2a04::1","CZCzechiaDEGermanyDDjiboutiDKDenmarkDDominicaDODominican RepublicDZAlgeriaECEcuadorEEEstoniaEG","CzechiaDEGermanyDDjiboutiDKDenmarkDDominicaDODominican RepublicDZAlgeriaEC","vadsRezinaRheinland-Pfalz
                                                                                                                                                                                                                  Rhode IslandRiau�Ribeira Grande de SantiagoRibnica
                                         Rif DimashqRigaRincon
Rio Gr","
WinnemuccaWinnen	WinnendenWinneWinnersWinnetka
Winnezeele	WinnfieldWinnicaWinnieWinning
Win","Village LLC>Winnen Gesellschaft ","50.583328","8.016670","lishing.net	winnen.dewinner-spedition.de
                                                                                                            winner.co.il	winner.lk
                                                                                                                                         winneram.comwinnercomm.comwinne","56456","0:00+01:00+02:00+03:00+04:00+04:30+05:00+","-","45","02662","2GMXX022GMXX022GMXX022GMXX022GMXX022GM","ickRenmarRennerodRennesRenoRenovo
RensselaerRensselaer FallRenteriaRentonRentRenvilleRepresRep","ckauZwolle-202204206208213214216218219220221222226228230231232234238240242244246","Pv6 ranges.-0000/0200/76000/120001004/005/006/0120101/001/02/0",".	+7Telecom-$1O1O / One2Free / New World Mobilit2degrees33 (2G)3Mob4ka9mobileA1A1.netAISAPTGASTELNET, ","466.000000","DCH","Pv6 ranges.U-IAB1IAB1-1IAB1-2IAB1-3IAB1-4IAB1-5IAB1-6IAB1-7IAB","1IAB19-1IAB19-1IAB19-19IAB19-IAB19-2","Pv6 ranges.-ALGOMA	Aanekoski	Abadiania
AbaetetubaAbairaAbaji
                     Abashiri","44153","Association
WinnenGmbHWinnet Br"
ip2location -v
IP2Location version 8.6.0

ip2location --data-file IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN.SAMPLE.BIN -b
BIN version 2023-5-29

can also reproduce when used by ipv6calc, so either IPv6 sample database of DB-26 is broken or library has issues with IPv6 DB-26 file.

IP2Location_get_net_speed vs IP2Location_get_netspeed

in IP2Location.h

IP2LocationRecord *IP2Location_get_net_speed(IP2Location *handler, char *ip);

in IP2Location.c

IP2LocationRecord *IP2Location_get_netspeed(IP2Location *handler, char *ip)

Trying to fix the PHP extension:
undefined symbol: IP2Location_get_net_speed
Or
implicit declaration of function 'IP2Location_get_netspeed'

But, please see issue #36

nginx multi process load database failed

when i set worker_processes to 1, everything is ok, but if i set worker_processes larger than 1, i got nginx error "can not load database file ", that means only one process can load database file?

Possible memory leak

Hello

I would like to report an issue that seems to cause segmentation fault in apache (with mod_ip2location) and libIP2Location
From the coredump i extracted this: IP2Location_free_record (libIP2Location.so.1)#12#6 0x00007fc39bbbdde0 ip2location_post_read_request (mod_ip2location.so)#12#7

I've tried to compile the latest version (8cc0f69), but the issue seems to persist.

Thank you very much for all your work!

Race in shared memory initialization

Hi,

First of all, thank you for this library!

I have several processes that query ip2location information and use IP2LOCATION_SHARED_MEMORY. The processes are started at the same time, and I noticed that when I restart the processes, I'm getting many ip2location errors.
I believe that what happens is that the first process creates the shared memory, and starts to load data into it. Before it finishes, a second processes tries to create the shared memory, sees that it already exists, and assumes that it's loaded, but it's not...
Is my understanding correct? are users of this library expected to synchronize calls to IP2Location_open_mem when using shared memory (didn't see this in the guide...)?

Thank you,

Eran

Shared-memory name

The shared-memory object under Windows is a bit strangely named:

\Sessions\1\BaseNamedObjects\/IP2location_Shm

since IP2Location.h has a #define IP2LOCATION_SHM "/IP2location_Shm".

Maybe it would be best to give CreateFileMapping() a suitable name depending on if UNICODE is defined etc?

IP2Location_api_version_num changed to IP2Location_api_version_number

it was a terrible idea to rename the api_version_number function - this totally kills backwards compatibilty for existing programs which already checking the version number (e.g. using dynload mechanism):

-unsigned long int IP2Location_api_version_number(void)
+unsigned long int IP2Location_api_version_num(void)
-unsigned long int IP2Location_api_version_number(void);
+unsigned long int IP2Location_api_version_num(void);
-	printf("IP2Location API version: %s (%lu)\n", IP2Location_api_version_string(), IP2Location_api_version_number());
+	printf("IP2Location API version: %s (%lu)\n", IP2Location_api_version_string(), IP2Location_api_version_num());

-> please re-add IP2Location_api_version_num and call then internally to IP2Location_api_version_number

BTW: such function should kept forever after introduced

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.