IP to Geo

IP to Geo Git Source Tree

Root/src/test.c

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

Archive Download this file

Branches

Tags