]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd/sd-netlink/test-local-addresses.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / libsystemd / sd-netlink / test-local-addresses.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
e9140aff
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2014 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
cf0fbc49 21#include "af-list.h"
b5efdb8a 22#include "alloc-util.h"
e9140aff
LP
23#include "in-addr-util.h"
24#include "local-addresses.h"
e9140aff
LP
25
26static void print_local_addresses(struct local_address *a, unsigned n) {
27 unsigned i;
28
29 for (i = 0; i < n; i++) {
30 _cleanup_free_ char *b = NULL;
31
32 assert_se(in_addr_to_string(a[i].family, &a[i].address, &b) >= 0);
33 printf("%s if%i scope=%i metric=%u address=%s\n", af_to_name(a[i].family), a[i].ifindex, a[i].scope, a[i].metric, b);
34 }
35}
36
37int main(int argc, char *argv[]) {
38 struct local_address *a;
39 int n;
40
41 a = NULL;
1d050e1e 42 n = local_addresses(NULL, 0, AF_UNSPEC, &a);
e9140aff
LP
43 assert_se(n >= 0);
44
45 printf("Local Addresses:\n");
46 print_local_addresses(a, (unsigned) n);
97b11eed 47 a = mfree(a);
e9140aff 48
1d050e1e 49 n = local_gateways(NULL, 0, AF_UNSPEC, &a);
e9140aff
LP
50 assert_se(n >= 0);
51
52 printf("Local Gateways:\n");
53 print_local_addresses(a, (unsigned) n);
54 free(a);
55
56 return 0;
57}