libnl  3.3.0
nl-neightbl-list.c
1 /*
2  * src/nl-neightbl-list.c Dump neighbour tables
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation version 2.1
7  * of the License.
8  *
9  * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
10  */
11 
12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/link.h>
14 
15 #include <linux/netlink.h>
16 
17 static void print_usage(void)
18 {
19  printf(
20  "Usage: nl-neightbl-list [OPTION]...\n"
21  "\n"
22  "Options\n"
23  " -f, --format=TYPE Output format { brief | details | stats }\n"
24  " -h, --help Show this help\n"
25  " -v, --version Show versioning information\n"
26  );
27  exit(0);
28 }
29 
30 int main(int argc, char *argv[])
31 {
32  struct nl_sock *sock;
33  struct nl_cache *neightbl_cache;
34  struct nl_dump_params params = {
36  .dp_fd = stdout,
37  };
38 
39  sock = nl_cli_alloc_socket();
40  nl_cli_connect(sock, NETLINK_ROUTE);
41  nl_cli_link_alloc_cache(sock);
42  neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table",
44 
45  for (;;) {
46  int c, optidx = 0;
47  static struct option long_opts[] = {
48  { "format", 1, 0, 'f' },
49  { "help", 0, 0, 'h' },
50  { "version", 0, 0, 'v' },
51  { 0, 0, 0, 0 }
52  };
53 
54  c = getopt_long(argc, argv, "f:hv", long_opts, &optidx);
55  if (c == -1)
56  break;
57 
58  switch (c) {
59  case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
60  case 'h': print_usage(); break;
61  case 'v': nl_cli_print_version(); break;
62  }
63  }
64 
65  nl_cache_dump(neightbl_cache, &params);
66 
67  return 0;
68 }
Dump object briefly on one line.
Definition: types.h:22
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:399
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
Definition: types.h:38
void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params)
Dump all elements of a cache.
Definition: cache.c:1202
Dumping parameters.
Definition: types.h:33