IP to Geo

IP to Geo Git Source Tree

Root/src/test.c

1#include <stdio.h>
2#include "ip_to_geo.h"
3
4#define IP(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
5
6static void do_test(int a, int b, int c, int d)
7{
8 const uint8_t* cc;
9 uint8_t ip[4] = {a, b, c, d};
10
11 cc = ip_to_geo(ip, 4);
12 printf("IP %d.%d.%d.%d : %s\n", a, b, c, d, (cc)?(char*)get_country_code(cc):"<none>");
13}
14
15int self_test()
16{
17 do_test(1,5,7,3);
18 do_test(1,5,255,4);
19 do_test(1,6,255,4);
20 do_test(2,0,0,0);
21 do_test(127,0,0,1);
22 do_test(1,55,3,12);
23 do_test(1,57,0,0);
24
25 return 0;
26}

Archive Download this file

Branches

Tags