]>
git.ipfire.org Git - people/ms/libloc.git/blob - src/test-network.c
2 libloc - A library to determine the location of someone on the Internet
4 Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
6 This program 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 2 of the License, or
9 (at your option) any later version.
11 This program 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.
23 #include <loc/libloc.h>
24 #include <loc/network.h>
25 #include <loc/writer.h>
27 int main(int argc
, char** argv
) {
35 struct loc_network_tree
* tree
;
36 err
= loc_network_tree_new(ctx
, &tree
);
38 fprintf(stderr
, "Could not create the network tree\n");
43 struct loc_network
* network1
;
44 err
= loc_network_new_from_string(ctx
, &network1
, "2001:db8::/32");
46 fprintf(stderr
, "Could not create the network\n");
50 err
= loc_network_set_country_code(network1
, "XX");
52 fprintf(stderr
, "Could not set country code\n");
56 // Adding network to the tree
57 err
= loc_network_tree_add_network(tree
, network1
);
59 fprintf(stderr
, "Could not add network to the tree\n");
64 err
= loc_network_tree_dump(tree
);
66 fprintf(stderr
, "Error dumping tree: %d\n", err
);
71 struct loc_writer
* writer
;
72 err
= loc_writer_new(ctx
, &writer
);
76 struct loc_network
* network2
;
77 err
= loc_writer_add_network(writer
, &network2
, "2001:db8:1::/48");
79 fprintf(stderr
, "Could not add network\n");
84 loc_network_set_country_code(network2
, "XX");
86 FILE* f
= fopen("test.db", "w");
88 fprintf(stderr
, "Could not open file for writing: %s\n", strerror(errno
));
92 err
= loc_writer_write(writer
, f
);
94 fprintf(stderr
, "Could not write database: %s\n", strerror(-err
));
99 loc_writer_unref(writer
);
101 loc_network_unref(network1
);
102 loc_network_tree_unref(tree
);