Tizen 2.1 base
[platform/upstream/libnl2.git] / src / genl-ctrl-list.c
1 /*
2  * src/genl-ctrl-list.c List Generic Netlink Controller
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
14 static struct nl_cache *alloc_genl_family_cache(struct nl_sock *sk)
15 {
16         return nl_cli_alloc_cache(sk, "generic netlink family",
17                            genl_ctrl_alloc_cache);
18 }
19
20 static void print_usage(void)
21 {
22         printf(
23         "Usage: genl-ctrl-list [OPTION]...\n"
24         "\n"
25         "Options\n"
26         " -f, --format=TYPE     Output format { brief | details | stats }\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 = {
38                 .dp_type = NL_DUMP_LINE,
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                         { "format", 1, 0, 'f' },
50                         { "help", 0, 0, 'h' },
51                         { "version", 0, 0, 'v' },
52                         { 0, 0, 0, 0 }
53                 };
54         
55                 c = getopt_long(argc, argv, "f:hv", long_opts, &optidx);
56                 if (c == -1)
57                         break;
58
59                 switch (c) {
60                 case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
61                 case 'h': print_usage(); break;
62                 case 'v': nl_cli_print_version(); break;
63                 }
64         }
65
66         nl_cache_dump(family_cache, &params);
67
68         return 0;
69 }