]> git.ipfire.org Git - location/libloc.git/blame - src/loc/network.h
database: Load networks from database
[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
MT
24
25struct loc_network;
26int loc_network_new(struct loc_ctx* ctx, struct loc_network** network,
27 struct in6_addr start_address, unsigned int prefix);
28int loc_network_new_from_string(struct loc_ctx* ctx, struct loc_network** network,
29 const char* address_string);
30struct loc_network* loc_network_ref(struct loc_network* network);
31struct loc_network* loc_network_unref(struct loc_network* network);
32char* loc_network_str(struct loc_network* network);
33
34const char* loc_network_get_country_code(struct loc_network* network);
35int loc_network_set_country_code(struct loc_network* network, const char* country_code);
36
71ff3e69
MT
37uint32_t loc_network_get_asn(struct loc_network* network);
38int loc_network_set_asn(struct loc_network* network, uint32_t asn);
39
f3e02bc5
MT
40int loc_network_to_database_v0(struct loc_network* network, struct loc_database_network_v0* dbobj);
41
3b5f4af2
MT
42struct loc_network_tree;
43int loc_network_tree_new(struct loc_ctx* ctx, struct loc_network_tree** tree);
44struct loc_network_tree* loc_network_tree_unref(struct loc_network_tree* tree);
438db08c 45struct loc_network_tree_node* loc_network_tree_get_root(struct loc_network_tree* tree);
f3e02bc5
MT
46int loc_network_tree_walk(struct loc_network_tree* tree,
47 int(*filter_callback)(struct loc_network* network, void* data),
48 int(*callback)(struct loc_network* network, void* data), void* data);
3b5f4af2
MT
49int loc_network_tree_dump(struct loc_network_tree* tree);
50int loc_network_tree_add_network(struct loc_network_tree* tree, struct loc_network* network);
f3e02bc5 51size_t loc_network_tree_count_networks(struct loc_network_tree* tree);
940f9c2b 52size_t loc_network_tree_count_nodes(struct loc_network_tree* tree);
3b5f4af2 53
438db08c
MT
54struct loc_network_tree_node;
55int loc_network_tree_node_new(struct loc_ctx* ctx, struct loc_network_tree_node** node);
56struct loc_network_tree_node* loc_network_tree_node_ref(struct loc_network_tree_node* node);
57struct loc_network_tree_node* loc_network_tree_node_unref(struct loc_network_tree_node* node);
58struct loc_network_tree_node* loc_network_tree_node_get(struct loc_network_tree_node* node, unsigned int index);
59
60int loc_network_tree_node_is_leaf(struct loc_network_tree_node* node);
61struct loc_network* loc_network_tree_node_get_network(struct loc_network_tree_node* node);
62
3b5f4af2 63#endif