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 library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library 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 GNU
14 Lesser General Public License for more details.
17 #ifndef LIBLOC_NETWORK_H
18 #define LIBLOC_NETWORK_H
20 #include <netinet/in.h>
22 #include <loc/libloc.h>
23 #include <loc/format.h>
25 enum loc_network_flags
{
26 LOC_NETWORK_FLAG_ANONYMOUS_PROXY
= (1 << 0), // A1
27 LOC_NETWORK_FLAG_SATELLITE_PROVIDER
= (1 << 1), // A2
28 LOC_NETWORK_FLAG_ANYCAST
= (1 << 2), // A3
32 int loc_network_new(struct loc_ctx
* ctx
, struct loc_network
** network
,
33 struct in6_addr
* start_address
, unsigned int prefix
);
34 int loc_network_new_from_string(struct loc_ctx
* ctx
, struct loc_network
** network
,
35 const char* address_string
);
36 struct loc_network
* loc_network_ref(struct loc_network
* network
);
37 struct loc_network
* loc_network_unref(struct loc_network
* network
);
38 char* loc_network_str(struct loc_network
* network
);
39 int loc_network_address_family(struct loc_network
* network
);
40 int loc_network_match_address(struct loc_network
* network
, const struct in6_addr
* address
);
42 const char* loc_network_get_country_code(struct loc_network
* network
);
43 int loc_network_set_country_code(struct loc_network
* network
, const char* country_code
);
44 int loc_network_match_country_code(struct loc_network
* network
, const char* country_code
);
46 uint32_t loc_network_get_asn(struct loc_network
* network
);
47 int loc_network_set_asn(struct loc_network
* network
, uint32_t asn
);
48 int loc_network_match_asn(struct loc_network
* network
, uint32_t asn
);
50 int loc_network_has_flag(struct loc_network
* network
, uint32_t flag
);
51 int loc_network_set_flag(struct loc_network
* network
, uint32_t flag
);
52 int loc_network_match_flag(struct loc_network
* network
, uint32_t flag
);
56 int loc_network_to_database_v0(struct loc_network
* network
, struct loc_database_network_v0
* dbobj
);
57 int loc_network_new_from_database_v0(struct loc_ctx
* ctx
, struct loc_network
** network
,
58 struct in6_addr
* address
, unsigned int prefix
, const struct loc_database_network_v0
* dbobj
);
60 struct loc_network_tree
;
61 int loc_network_tree_new(struct loc_ctx
* ctx
, struct loc_network_tree
** tree
);
62 struct loc_network_tree
* loc_network_tree_unref(struct loc_network_tree
* tree
);
63 struct loc_network_tree_node
* loc_network_tree_get_root(struct loc_network_tree
* tree
);
64 int loc_network_tree_walk(struct loc_network_tree
* tree
,
65 int(*filter_callback
)(struct loc_network
* network
, void* data
),
66 int(*callback
)(struct loc_network
* network
, void* data
), void* data
);
67 int loc_network_tree_dump(struct loc_network_tree
* tree
);
68 int loc_network_tree_add_network(struct loc_network_tree
* tree
, struct loc_network
* network
);
69 size_t loc_network_tree_count_networks(struct loc_network_tree
* tree
);
70 size_t loc_network_tree_count_nodes(struct loc_network_tree
* tree
);
72 struct loc_network_tree_node
;
73 int loc_network_tree_node_new(struct loc_ctx
* ctx
, struct loc_network_tree_node
** node
);
74 struct loc_network_tree_node
* loc_network_tree_node_ref(struct loc_network_tree_node
* node
);
75 struct loc_network_tree_node
* loc_network_tree_node_unref(struct loc_network_tree_node
* node
);
76 struct loc_network_tree_node
* loc_network_tree_node_get(struct loc_network_tree_node
* node
, unsigned int index
);
78 int loc_network_tree_node_is_leaf(struct loc_network_tree_node
* node
);
79 struct loc_network
* loc_network_tree_node_get_network(struct loc_network_tree_node
* node
);