libnl  3.2.24-rc1
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 static struct nl_cache *alloc_genl_family_cache(struct nl_sock *sk)
15 {
16  return nl_cli_alloc_cache(sk, "generic netlink family",
18 }
19 
20 static void print_usage(void)
21 {
22  printf(
23  "Usage: genl-ctrl-list [--details]\n"
24  "\n"
25  "Options\n"
26  " -d, --details Include detailed information in the list\n"
27  " -h, --help Show this help\n"
28  " -v, --version Show versioning information\n"
29  );
30  exit(0);
31 }
32 
33 int main(int argc, char *argv[])
34 {
35  struct nl_sock *sock;
36  struct nl_cache *family_cache;
37  struct nl_dump_params params = {
39  .dp_fd = stdout,
40  };
41 
42  sock = nl_cli_alloc_socket();
43  nl_cli_connect(sock, NETLINK_GENERIC);
44  family_cache = alloc_genl_family_cache(sock);
45 
46  for (;;) {
47  int c, optidx = 0;
48  static struct option long_opts[] = {
49  { "details", 0, 0, 'd' },
50  { "format", 1, 0, 'f' },
51  { "help", 0, 0, 'h' },
52  { "version", 0, 0, 'v' },
53  { 0, 0, 0, 0 }
54  };
55 
56  c = getopt_long(argc, argv, "df:hv", long_opts, &optidx);
57  if (c == -1)
58  break;
59 
60  switch (c) {
61  case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
62  case 'd': params.dp_type = NL_DUMP_DETAILS; break;
63  case 'h': print_usage(); break;
64  case 'v': nl_cli_print_version(); break;
65  }
66  }
67 
68  nl_cache_dump(family_cache, &params);
69 
70  return 0;
71 }