2016-02-17 18:15:04 +01:00
|
|
|
/*
|
|
|
|
Copyright 2016 Grégory Soutadé
|
|
|
|
|
|
|
|
This file is part of iptogeo.
|
|
|
|
|
|
|
|
iptogeo is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
iptogeo is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with iptogeo. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-31 11:42:28 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "ip_to_geo.h"
|
|
|
|
|
|
|
|
#define IP(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
|
|
|
|
|
|
|
|
static void do_test(int a, int b, int c, int d)
|
|
|
|
{
|
|
|
|
const uint8_t* cc;
|
2016-02-04 20:39:50 +01:00
|
|
|
uint8_t ip[4] = {a, b, c, d};
|
2016-01-31 11:42:28 +01:00
|
|
|
|
2016-02-04 20:39:50 +01:00
|
|
|
cc = ip_to_geo(ip, 4);
|
2016-01-31 11:42:28 +01:00
|
|
|
printf("IP %d.%d.%d.%d : %s\n", a, b, c, d, (cc)?(char*)get_country_code(cc):"<none>");
|
|
|
|
}
|
|
|
|
|
|
|
|
int self_test()
|
|
|
|
{
|
|
|
|
do_test(1,5,7,3);
|
|
|
|
do_test(1,5,255,4);
|
|
|
|
do_test(1,6,255,4);
|
|
|
|
do_test(2,0,0,0);
|
|
|
|
do_test(127,0,0,1);
|
|
|
|
do_test(1,55,3,12);
|
|
|
|
do_test(1,57,0,0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|