1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * Copyright (c) 2003-2012 Thomas Graf <[email protected]>
4 */
5
6 #include "nl-default.h"
7
8 #include <linux/genetlink.h>
9
10 #include <netlink/cli/utils.h>
11
alloc_genl_family_cache(struct nl_sock * sk)12 static struct nl_cache *alloc_genl_family_cache(struct nl_sock *sk)
13 {
14 return nl_cli_alloc_cache(sk, "generic netlink family",
15 genl_ctrl_alloc_cache);
16 }
17
print_usage(void)18 static void print_usage(void)
19 {
20 printf(
21 "Usage: genl-ctrl-list [--details]\n"
22 "\n"
23 "Options\n"
24 " -d, --details Include detailed information in the list\n"
25 " -h, --help Show this help\n"
26 " -v, --version Show versioning information\n"
27 );
28 exit(0);
29 }
30
main(int argc,char * argv[])31 int main(int argc, char *argv[])
32 {
33 struct nl_sock *sock;
34 struct nl_cache *family_cache;
35 struct nl_dump_params params = {
36 .dp_type = NL_DUMP_LINE,
37 .dp_fd = stdout,
38 };
39
40 sock = nl_cli_alloc_socket();
41 nl_cli_connect(sock, NETLINK_GENERIC);
42 family_cache = alloc_genl_family_cache(sock);
43
44 for (;;) {
45 int c, optidx = 0;
46 static struct option long_opts[] = {
47 { "details", 0, 0, 'd' },
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, "df: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 'd': params.dp_type = NL_DUMP_DETAILS; break;
61 case 'h': print_usage(); break;
62 case 'v': nl_cli_print_version(); break;
63 }
64 }
65
66 nl_cache_dump(family_cache, ¶ms);
67
68 return 0;
69 }
70