libnl: /data/src/libnl3/src/nl-neightbl-list.c Source File

libnl 3.10.0

nl-neightbl-list.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
4 */
5
6#include "nl-default.h"
7
8#include <linux/netlink.h>
9
10#include <netlink/cli/utils.h>
11#include <netlink/cli/link.h>
12
13static void print_usage(void)
14{
15 printf(
16 "Usage: nl-neightbl-list [OPTION]...\n"
17 "\n"
18 "Options\n"
19 " -f, --format=TYPE Output format { brief | details | stats }\n"
20 " -h, --help Show this help\n"
21 " -v, --version Show versioning information\n"
22 );
23 exit(0);
24}
25
26int main(int argc, char *argv[])
27{
28 struct nl_sock *sock;
29 struct nl_cache *neightbl_cache;
30 struct nl_dump_params params = {
31 .dp_type = NL_DUMP_LINE,
32 .dp_fd = stdout,
33 };
34
35 sock = nl_cli_alloc_socket();
36 nl_cli_connect(sock, NETLINK_ROUTE);
37 nl_cli_link_alloc_cache(sock);
38 neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table",
39 rtnl_neightbl_alloc_cache);
40
41 for (;;) {
42 int c, optidx = 0;
43 static struct option long_opts[] = {
44 { "format", 1, 0, 'f' },
45 { "help", 0, 0, 'h' },
46 { "version", 0, 0, 'v' },
47 { 0, 0, 0, 0 }
48 };
49
50 c = getopt_long(argc, argv, "f:hv", long_opts, &optidx);
51 if (c == -1)
52 break;
53
54 switch (c) {
55 case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
56 case 'h': print_usage(); break;
57 case 'v': nl_cli_print_version(); break;
58 }
59 }
60
61 nl_cache_dump(neightbl_cache, &params);
62
63 return 0;
64}
nl_cache_dump
void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params)
Dump all elements of a cache.
Definition cache.c:1203
rtnl_neightbl_alloc_cache
int rtnl_neightbl_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
Build a neighbour table cache including all neighbour tables currently configured in the kernel.
Definition neightbl.c:509
NL_DUMP_LINE
@ NL_DUMP_LINE
Dump object briefly on one line.
Definition types.h:20
nl_dump_params
Dumping parameters.
Definition types.h:32
nl_dump_params::dp_type
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
Definition types.h:36