Imported Upstream version 1.1
[platform/upstream/libnl1.git] / src / genl-ctrl-dump.c
1 /*
2  * src/genl-ctrl-dump.c Dump 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-2006 Thomas Graf <tgraf@suug.ch>
10  */
11
12 #include "utils.h"
13
14 static void print_usage(void)
15 {
16         printf(
17         "Usage: genl-ctrl-dump <mode> [<filter>]\n"
18         "  mode := { brief | detailed | stats }\n"
19         "  filter := \n");
20         exit(1);
21 }
22
23 int main(int argc, char *argv[])
24 {
25         struct nl_handle *nlh;
26         struct nl_cache *family_cache;
27         struct nl_dump_params params = {
28                 .dp_fd = stdout,
29                 .dp_type = NL_DUMP_BRIEF
30         };
31         int err = 1;
32
33         if (nltool_init(argc, argv) < 0)
34                 return -1;
35
36         if (argc < 2 || !strcmp(argv[1], "-h"))
37                 print_usage();
38
39         nlh = nltool_alloc_handle();
40         if (!nlh)
41                 return -1;
42
43         if (genl_connect(nlh) < 0) {
44                 fprintf(stderr, "Unable to connect generic netlink socket%s\n",
45                         nl_geterror());
46                 goto errout;
47         }
48
49         family_cache = nltool_alloc_genl_family_cache(nlh);
50         if (!family_cache)
51                 goto errout;
52
53         params.dp_type = nltool_parse_dumptype(argv[1]);
54         if (params.dp_type < 0)
55                 goto errout;
56
57         //get_filter(link, argc, argv, 2, link_cache);
58         nl_cache_dump(family_cache, &params);
59         nl_cache_free(family_cache);
60         err = 0;
61 errout:
62         nl_close(nlh);
63         nl_handle_destroy(nlh);
64         return err;
65 }