]>
git.ipfire.org Git - location/libloc.git/blob - src/test-network-list.c
3061d63e67e6c0b22ab323dbe504c825e6ca7c3d
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 program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program 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
14 GNU General Public License for more details.
24 #include <loc/libloc.h>
25 #include <loc/network.h>
26 #include <loc/network-list.h>
28 int main(int argc
, char** argv
) {
36 // Enable debug logging
37 loc_set_log_priority(ctx
, LOG_DEBUG
);
40 struct loc_network
* network1
;
41 err
= loc_network_new_from_string(ctx
, &network1
, "2001:db8::/32");
43 fprintf(stderr
, "Could not create the network1\n");
47 struct loc_network
* subnet1
;
48 err
= loc_network_new_from_string(ctx
, &subnet1
, "2001:db8:a::/48");
50 fprintf(stderr
, "Could not create the subnet1\n");
54 struct loc_network
* subnet2
;
55 err
= loc_network_new_from_string(ctx
, &subnet2
, "2001:db8:b::/48");
57 fprintf(stderr
, "Could not create the subnet2\n");
61 // Make a list with both subnets
62 struct loc_network_list
* subnets
;
63 err
= loc_network_list_new(ctx
, &subnets
);
65 fprintf(stderr
, "Could not create subnets list\n");
69 size_t size
= loc_network_list_size(subnets
);
71 fprintf(stderr
, "The list is not empty: %zu\n", size
);
75 err
= loc_network_list_push(subnets
, subnet1
);
77 fprintf(stderr
, "Could not add subnet1 to subnets list\n");
81 if (loc_network_list_empty(subnets
)) {
82 fprintf(stderr
, "The subnets list reports that it is empty\n");
86 err
= loc_network_list_push(subnets
, subnet2
);
88 fprintf(stderr
, "Could not add subnet2 to subnets list\n");
92 size
= loc_network_list_size(subnets
);
94 fprintf(stderr
, "Network list is reporting an incorrect size: %zu\n", size
);
98 // Exclude subnet1 from network1
99 struct loc_network_list
* excluded
= loc_network_exclude(network1
, subnet1
);
101 fprintf(stderr
, "Received an empty result from loc_network_exclude() for subnet1\n");
105 loc_network_list_dump(excluded
);
107 // Exclude all subnets from network1
108 excluded
= loc_network_exclude_list(network1
, subnets
);
110 fprintf(stderr
, "Received an empty result from loc_network_exclude() for subnets\n");
114 loc_network_list_dump(excluded
);
117 loc_network_list_unref(excluded
);
119 loc_network_list_unref(subnets
);
120 loc_network_unref(network1
);
121 loc_network_unref(subnet1
);
122 loc_network_unref(subnet2
);