]>
Commit | Line | Data |
---|---|---|
3b5f4af2 MT |
1 | /* |
2 | libloc - A library to determine the location of someone on the Internet | |
3 | ||
4 | Copyright (C) 2017 IPFire Development Team <info@ipfire.org> | |
5 | ||
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. | |
10 | ||
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. | |
15 | */ | |
16 | ||
17 | #include <stdio.h> | |
18 | #include <stddef.h> | |
19 | #include <stdlib.h> | |
20 | #include <string.h> | |
21 | ||
22 | #include <loc/libloc.h> | |
23 | #include <loc/network.h> | |
24 | ||
25 | int main(int argc, char** argv) { | |
26 | int err; | |
27 | ||
28 | struct loc_ctx* ctx; | |
29 | err = loc_new(&ctx); | |
30 | if (err < 0) | |
31 | exit(EXIT_FAILURE); | |
32 | ||
33 | struct loc_network_tree* tree; | |
34 | err = loc_network_tree_new(ctx, &tree); | |
35 | if (err) { | |
36 | fprintf(stderr, "Could not create the network tree\n"); | |
37 | exit(EXIT_FAILURE); | |
38 | } | |
39 | ||
40 | // Create a network | |
41 | struct loc_network* network1; | |
42 | err = loc_network_new_from_string(ctx, &network1, "2001:db8::/32"); | |
43 | if (err) { | |
44 | fprintf(stderr, "Could not create the network\n"); | |
45 | exit(EXIT_FAILURE); | |
46 | } | |
47 | ||
48 | err = loc_network_set_country_code(network1, "XX"); | |
49 | if (err) { | |
50 | fprintf(stderr, "Could not set country code\n"); | |
51 | exit(EXIT_FAILURE); | |
52 | } | |
53 | ||
54 | // Adding network to the tree | |
55 | err = loc_network_tree_add_network(tree, network1); | |
56 | if (err) { | |
57 | fprintf(stderr, "Could not add network to the tree\n"); | |
58 | exit(EXIT_FAILURE); | |
59 | } | |
60 | ||
61 | // Dump the tree | |
62 | err = loc_network_tree_dump(tree); | |
63 | if (err) { | |
64 | fprintf(stderr, "Error dumping tree: %d\n", err); | |
65 | exit(EXIT_FAILURE); | |
66 | } | |
67 | ||
68 | loc_network_unref(network1); | |
69 | loc_network_tree_unref(tree); | |
70 | loc_unref(ctx); | |
71 | ||
72 | return EXIT_SUCCESS; | |
73 | } |