]>
Commit | Line | Data |
---|---|---|
3b5f4af2 MT |
1 | /* |
2 | libloc - A library to determine the location of someone on the Internet | |
3 | ||
e17e804e | 4 | Copyright (C) 2017-2021 IPFire Development Team <info@ipfire.org> |
3b5f4af2 MT |
5 | |
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. | |
10 | ||
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. | |
15 | */ | |
16 | ||
17 | #ifndef LIBLOC_NETWORK_H | |
18 | #define LIBLOC_NETWORK_H | |
19 | ||
20 | #include <netinet/in.h> | |
21 | ||
c12a1385 MT |
22 | #include <libloc/libloc.h> |
23 | #include <libloc/format.h> | |
24 | #include <libloc/network-list.h> | |
3b5f4af2 | 25 | |
a293f829 MT |
26 | enum loc_network_flags { |
27 | LOC_NETWORK_FLAG_ANONYMOUS_PROXY = (1 << 0), // A1 | |
28 | LOC_NETWORK_FLAG_SATELLITE_PROVIDER = (1 << 1), // A2 | |
29 | LOC_NETWORK_FLAG_ANYCAST = (1 << 2), // A3 | |
e17e804e | 30 | LOC_NETWORK_FLAG_DROP = (1 << 3), // XD |
a293f829 MT |
31 | }; |
32 | ||
3b5f4af2 MT |
33 | struct loc_network; |
34 | int loc_network_new(struct loc_ctx* ctx, struct loc_network** network, | |
ce4f5752 | 35 | struct in6_addr* first_address, unsigned int prefix); |
3b5f4af2 MT |
36 | int loc_network_new_from_string(struct loc_ctx* ctx, struct loc_network** network, |
37 | const char* address_string); | |
38 | struct loc_network* loc_network_ref(struct loc_network* network); | |
39 | struct loc_network* loc_network_unref(struct loc_network* network); | |
0a0a289a | 40 | const char* loc_network_str(struct loc_network* network); |
44e5ef71 | 41 | int loc_network_address_family(struct loc_network* network); |
7fe6a218 | 42 | unsigned int loc_network_prefix(struct loc_network* network); |
2b9338ea | 43 | |
a1a00053 | 44 | const struct in6_addr* loc_network_get_first_address(struct loc_network* network); |
0a0a289a | 45 | const char* loc_network_format_first_address(struct loc_network* network); |
a1a00053 | 46 | const struct in6_addr* loc_network_get_last_address(struct loc_network* network); |
0a0a289a | 47 | const char* loc_network_format_last_address(struct loc_network* network); |
0258d3c9 | 48 | int loc_network_matches_address(struct loc_network* network, const struct in6_addr* address); |
3b5f4af2 MT |
49 | |
50 | const char* loc_network_get_country_code(struct loc_network* network); | |
51 | int loc_network_set_country_code(struct loc_network* network, const char* country_code); | |
0258d3c9 | 52 | int loc_network_matches_country_code(struct loc_network* network, const char* country_code); |
3b5f4af2 | 53 | |
71ff3e69 MT |
54 | uint32_t loc_network_get_asn(struct loc_network* network); |
55 | int loc_network_set_asn(struct loc_network* network, uint32_t asn); | |
56 | ||
a99e7c2b MT |
57 | int loc_network_has_flag(struct loc_network* network, uint32_t flag); |
58 | int loc_network_set_flag(struct loc_network* network, uint32_t flag); | |
a99e7c2b | 59 | |
af4689bf | 60 | int loc_network_cmp(struct loc_network* self, struct loc_network* other); |
6159d384 | 61 | int loc_network_overlaps(struct loc_network* self, struct loc_network* other); |
33a051e0 | 62 | int loc_network_is_subnet(struct loc_network* self, struct loc_network* other); |
a5967330 | 63 | int loc_network_subnets(struct loc_network* network, struct loc_network** subnet1, struct loc_network** subnet2); |
850e7516 MT |
64 | struct loc_network_list* loc_network_exclude( |
65 | struct loc_network* self, struct loc_network* other); | |
add5bb65 MT |
66 | struct loc_network_list* loc_network_exclude_list( |
67 | struct loc_network* network, struct loc_network_list* list); | |
43554dc4 | 68 | |
30ac38a1 MT |
69 | #ifdef LIBLOC_PRIVATE |
70 | ||
fe8277ed | 71 | int loc_network_properties_cmp(struct loc_network* self, struct loc_network* other); |
a92139f1 | 72 | unsigned int loc_network_raw_prefix(struct loc_network* network); |
fe8277ed | 73 | |
b904896a MT |
74 | int loc_network_to_database_v1(struct loc_network* network, struct loc_database_network_v1* dbobj); |
75 | int loc_network_new_from_database_v1(struct loc_ctx* ctx, struct loc_network** network, | |
76 | struct in6_addr* address, unsigned int prefix, const struct loc_database_network_v1* dbobj); | |
f3e02bc5 | 77 | |
fe8277ed | 78 | int loc_network_merge(struct loc_network** n, struct loc_network* n1, struct loc_network* n2); |
f6c6b8d6 | 79 | |
3b5f4af2 | 80 | #endif |
30ac38a1 | 81 | #endif |