]> git.ipfire.org Git - location/libloc.git/blame - src/loc/network.h
network: Export family, first_address and last_address in Python
[location/libloc.git] / src / loc / network.h
CommitLineData
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 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>
f3e02bc5 23#include <loc/format.h>
3b5f4af2 24
a293f829
MT
25enum 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
29};
30
3b5f4af2
MT
31struct loc_network;
32int loc_network_new(struct loc_ctx* ctx, struct loc_network** network,
ce4f5752 33 struct in6_addr* first_address, unsigned int prefix);
3b5f4af2
MT
34int loc_network_new_from_string(struct loc_ctx* ctx, struct loc_network** network,
35 const char* address_string);
36struct loc_network* loc_network_ref(struct loc_network* network);
37struct loc_network* loc_network_unref(struct loc_network* network);
38char* loc_network_str(struct loc_network* network);
44e5ef71 39int loc_network_address_family(struct loc_network* network);
2b9338ea
MT
40
41char* loc_network_format_first_address(struct loc_network* network);
42char* loc_network_format_last_address(struct loc_network* network);
2a30e4de 43int loc_network_match_address(struct loc_network* network, const struct in6_addr* address);
3b5f4af2
MT
44
45const char* loc_network_get_country_code(struct loc_network* network);
46int loc_network_set_country_code(struct loc_network* network, const char* country_code);
e3f696c1 47int loc_network_match_country_code(struct loc_network* network, const char* country_code);
3b5f4af2 48
71ff3e69
MT
49uint32_t loc_network_get_asn(struct loc_network* network);
50int loc_network_set_asn(struct loc_network* network, uint32_t asn);
82910b95 51int loc_network_match_asn(struct loc_network* network, uint32_t asn);
71ff3e69 52
a99e7c2b
MT
53int loc_network_has_flag(struct loc_network* network, uint32_t flag);
54int loc_network_set_flag(struct loc_network* network, uint32_t flag);
55int loc_network_match_flag(struct loc_network* network, uint32_t flag);
56
43554dc4
MT
57int loc_network_is_subnet_of(struct loc_network* self, struct loc_network* other);
58
30ac38a1
MT
59#ifdef LIBLOC_PRIVATE
60
b904896a
MT
61int loc_network_to_database_v1(struct loc_network* network, struct loc_database_network_v1* dbobj);
62int loc_network_new_from_database_v1(struct loc_ctx* ctx, struct loc_network** network,
63 struct in6_addr* address, unsigned int prefix, const struct loc_database_network_v1* dbobj);
f3e02bc5 64
3b5f4af2
MT
65struct loc_network_tree;
66int loc_network_tree_new(struct loc_ctx* ctx, struct loc_network_tree** tree);
67struct loc_network_tree* loc_network_tree_unref(struct loc_network_tree* tree);
438db08c 68struct loc_network_tree_node* loc_network_tree_get_root(struct loc_network_tree* tree);
f3e02bc5
MT
69int loc_network_tree_walk(struct loc_network_tree* tree,
70 int(*filter_callback)(struct loc_network* network, void* data),
71 int(*callback)(struct loc_network* network, void* data), void* data);
3b5f4af2
MT
72int loc_network_tree_dump(struct loc_network_tree* tree);
73int loc_network_tree_add_network(struct loc_network_tree* tree, struct loc_network* network);
f3e02bc5 74size_t loc_network_tree_count_networks(struct loc_network_tree* tree);
940f9c2b 75size_t loc_network_tree_count_nodes(struct loc_network_tree* tree);
3b5f4af2 76
438db08c
MT
77struct loc_network_tree_node;
78int loc_network_tree_node_new(struct loc_ctx* ctx, struct loc_network_tree_node** node);
79struct loc_network_tree_node* loc_network_tree_node_ref(struct loc_network_tree_node* node);
80struct loc_network_tree_node* loc_network_tree_node_unref(struct loc_network_tree_node* node);
81struct loc_network_tree_node* loc_network_tree_node_get(struct loc_network_tree_node* node, unsigned int index);
82
83int loc_network_tree_node_is_leaf(struct loc_network_tree_node* node);
84struct loc_network* loc_network_tree_node_get_network(struct loc_network_tree_node* node);
85
3b5f4af2 86#endif
30ac38a1 87#endif