libnl  3.4.0
genl-ctrl-list.c
1 /*
2  * src/genl-ctrl-list.c List Generic Netlink Families
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-2012 Thomas Graf <tgraf@suug.ch>
10  */
11 
12 #include <netlink/cli/utils.h>
13 
14 #include <linux/genetlink.h>
15 
16 static struct nl_cache *alloc_genl_family_cache(struct nl_sock *sk)
17 {
18  return nl_cli_alloc_cache(sk, "generic netlink family",
20 }
21 
22 static void print_usage(void)
23 {
24  printf(
25  "Usage: genl-ctrl-list [--details]\n"
26  "\n"
27  "Options\n"
28  " -d, --details Include detailed information in the list\n"
29  " -h, --help Show this help\n"
30  " -v, --version Show versioning information\n"
31  );
32  exit(0);
33 }
34 
35 int main(int argc, char *argv[])
36 {
37  struct nl_sock *sock;
38  struct nl_cache *family_cache;
39  struct nl_dump_params params = {
41  .dp_fd = stdout,
42  };
43 
44  sock = nl_cli_alloc_socket();
45  nl_cli_connect(sock, NETLINK_GENERIC);
46  family_cache = alloc_genl_family_cache(sock);
47 
48  for (;;) {
49  int c, optidx = 0;
50  static struct option long_opts[] = {
51  { "details", 0, 0, 'd' },
52  { "format", 1, 0, 'f' },
53  { "help", 0, 0, 'h' },
54  { "version", 0, 0, 'v' },
55  { 0, 0, 0, 0 }
56  };
57 
58  c = getopt_long(argc, argv, "df:hv", long_opts, &optidx);
59  if (c == -1)
60  break;
61 
62  switch (c) {
63  case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
64  case 'd': params.dp_type = NL_DUMP_DETAILS; break;
65  case 'h': print_usage(); break;
66  case 'v': nl_cli_print_version(); break;
67  }
68  }
69 
70  nl_cache_dump(family_cache, &params);
71 
72  return 0;
73 }
Dump object briefly on one line.
Definition: types.h:22
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
Definition: types.h:38
int genl_ctrl_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
Allocate a new controller cache.
Definition: ctrl.c:333
Dump all attributes but no statistics.
Definition: types.h:23
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