230e059bc7d0fbf802a7c06a99195ea2c53e8d22
[libnl.git] / src / nl-neightbl-dump.c
1 /*
2  * src/nl-neightbl-dump.c     Dump neighbour tables
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: nl-neightbl-dump <mode> [<filter>]\n"
18         "  mode := { brief | detailed | stats | xml }\n"
19         "  filter :=\n");
20         exit(1);
21 }
22
23 int main(int argc, char *argv[])
24 {
25         int err = -1;
26         struct nl_handle *nlh;
27         struct nl_cache *ntc, *lc;
28         struct nl_dump_params params = {
29                 .dp_fd = stdout,
30                 .dp_type = NL_DUMP_BRIEF,
31         };
32
33         if (argc < 2)
34                 print_usage();
35
36         if (nltool_init(argc, argv) < 0)
37                 return -1;
38
39         nlh = nl_handle_alloc_nondefault(nltool_cbset);
40         if (!nlh)
41                 return -1;
42
43         if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
44                 goto errout;
45
46         ntc = nltool_alloc_neightbl_cache(nlh);
47         if (!ntc)
48                 goto errout_close;
49
50         lc = nltool_alloc_link_cache(nlh);
51         if (!lc)
52                 goto errout_ntbl_cache;
53
54         params.dp_type = nltool_parse_dumptype(argv[1]);
55         if (params.dp_type < 0)
56                 goto errout_link_cache;
57
58         nl_cache_dump(ntc, &params);
59         err = 0;
60
61 errout_link_cache:
62         nl_cache_free(lc);
63 errout_ntbl_cache:
64         nl_cache_free(ntc);
65 errout_close:
66         nl_close(nlh);
67 errout:
68         nl_handle_destroy(nlh);
69         return err;
70 }