]> git.ipfire.org Git - people/ms/libloc.git/blame_incremental - src/loc/network.h
network-list: Make this a sorted list
[people/ms/libloc.git] / src / loc / network.h
... / ...
CommitLineData
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 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
22#include <loc/libloc.h>
23#include <loc/format.h>
24#include <loc/network-list.h>
25
26enum 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
30};
31
32struct loc_network;
33int loc_network_new(struct loc_ctx* ctx, struct loc_network** network,
34 struct in6_addr* first_address, unsigned int prefix);
35int loc_network_new_from_string(struct loc_ctx* ctx, struct loc_network** network,
36 const char* address_string);
37struct loc_network* loc_network_ref(struct loc_network* network);
38struct loc_network* loc_network_unref(struct loc_network* network);
39char* loc_network_str(struct loc_network* network);
40int loc_network_address_family(struct loc_network* network);
41unsigned int loc_network_prefix(struct loc_network* network);
42
43const struct in6_addr* loc_network_get_first_address(struct loc_network* network);
44char* loc_network_format_first_address(struct loc_network* network);
45const struct in6_addr* loc_network_get_last_address(struct loc_network* network);
46char* loc_network_format_last_address(struct loc_network* network);
47int loc_network_match_address(struct loc_network* network, const struct in6_addr* address);
48
49const char* loc_network_get_country_code(struct loc_network* network);
50int loc_network_set_country_code(struct loc_network* network, const char* country_code);
51int loc_network_match_country_code(struct loc_network* network, const char* country_code);
52
53uint32_t loc_network_get_asn(struct loc_network* network);
54int loc_network_set_asn(struct loc_network* network, uint32_t asn);
55int loc_network_match_asn(struct loc_network* network, uint32_t asn);
56
57int loc_network_has_flag(struct loc_network* network, uint32_t flag);
58int loc_network_set_flag(struct loc_network* network, uint32_t flag);
59int loc_network_match_flag(struct loc_network* network, uint32_t flag);
60
61int loc_network_cmp(struct loc_network* self, struct loc_network* other);
62int loc_network_eq(struct loc_network* self, struct loc_network* other);
63int loc_network_gt(struct loc_network* self, struct loc_network* other);
64int loc_network_overlaps(struct loc_network* self, struct loc_network* other);
65int loc_network_is_subnet(struct loc_network* self, struct loc_network* other);
66int loc_network_subnets(struct loc_network* network, struct loc_network** subnet1, struct loc_network** subnet2);
67struct loc_network_list* loc_network_exclude(
68 struct loc_network* self, struct loc_network* other);
69struct loc_network_list* loc_network_exclude_list(
70 struct loc_network* network, struct loc_network_list* list);
71
72#ifdef LIBLOC_PRIVATE
73
74int loc_network_to_database_v1(struct loc_network* network, struct loc_database_network_v1* dbobj);
75int 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);
77
78struct loc_network_tree;
79int loc_network_tree_new(struct loc_ctx* ctx, struct loc_network_tree** tree);
80struct loc_network_tree* loc_network_tree_unref(struct loc_network_tree* tree);
81struct loc_network_tree_node* loc_network_tree_get_root(struct loc_network_tree* tree);
82int loc_network_tree_walk(struct loc_network_tree* tree,
83 int(*filter_callback)(struct loc_network* network, void* data),
84 int(*callback)(struct loc_network* network, void* data), void* data);
85int loc_network_tree_dump(struct loc_network_tree* tree);
86int loc_network_tree_add_network(struct loc_network_tree* tree, struct loc_network* network);
87size_t loc_network_tree_count_networks(struct loc_network_tree* tree);
88size_t loc_network_tree_count_nodes(struct loc_network_tree* tree);
89
90struct loc_network_tree_node;
91int loc_network_tree_node_new(struct loc_ctx* ctx, struct loc_network_tree_node** node);
92struct loc_network_tree_node* loc_network_tree_node_ref(struct loc_network_tree_node* node);
93struct loc_network_tree_node* loc_network_tree_node_unref(struct loc_network_tree_node* node);
94struct loc_network_tree_node* loc_network_tree_node_get(struct loc_network_tree_node* node, unsigned int index);
95
96int loc_network_tree_node_is_leaf(struct loc_network_tree_node* node);
97struct loc_network* loc_network_tree_node_get_network(struct loc_network_tree_node* node);
98
99#endif
100#endif