Created
January 19, 2016 20:36
-
-
Save jroyalty/8192d468d15793c8bbc7 to your computer and use it in GitHub Desktop.
Netmask for IPv4 source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <maxminddb.h> | |
int main(int argc, const char * argv[]) { | |
MMDB_s *mmdb = (MMDB_s *)malloc(sizeof(MMDB_s)); | |
MMDB_open("/tmp/GeoIP2-City_20160105/GeoIP2-City.mmdb", | |
MMDB_MODE_MMAP, mmdb); | |
int gai_error = 0; | |
int mmdb_error = MMDB_SUCCESS; | |
MMDB_lookup_result_s res = MMDB_lookup_string(mmdb, "71.183.42.223", &gai_error, &mmdb_error); | |
// Result from legacy database is: 71.183.42.223 = 24 | |
// The following returns: Netmask as returned: 120, corrected: 24 | |
printf("Netmask as returned: %d, corrected: %d\n", res.netmask, res.netmask - mmdb->ipv4_start_node.netmask); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment