oops
[libnl.git] / src / nl-link-dump.c
1 /*
2  * src/nl-link-dump.c   Dump link attributes
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-link-dump <mode> [<filter>]\n"
18         "  mode := { brief | detailed | stats | xml }\n"
19         "  filter := [dev DEV] [mtu MTU] [txqlen TXQLEN] [weight WEIGHT] [link LINK]\n"
20         "            [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n"
21         "            [{ up | down }] [{ arp | noarp }] [{ promisc | nopromisc }]\n"
22         "            [{ dynamic | nodynamic }] [{ multicast | nomulticast }]\n"
23         "            [{ trailers | notrailers }] [{ allmulticast | noallmulticast }]\n");
24         exit(1);
25 }
26
27 #include "f_link.c"
28
29 int main(int argc, char *argv[])
30 {
31         struct nl_handle *nlh;
32         struct nl_cache *link_cache;
33         struct rtnl_link *link;
34         struct nl_dump_params params = {
35                 .dp_fd = stdout,
36                 .dp_type = NL_DUMP_BRIEF
37         };
38         int err = 1;
39
40         if (nltool_init(argc, argv) < 0)
41                 return -1;
42
43         if (argc < 2 || !strcmp(argv[1], "-h"))
44                 print_usage();
45
46         nlh = nl_handle_alloc_nondefault(nltool_cbset);
47         if (!nlh)
48                 return -1;
49
50         link = rtnl_link_alloc();
51         if (!link)
52                 goto errout;
53
54         if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
55                 goto errout_put;
56
57         link_cache = nltool_alloc_link_cache(nlh);
58         if (!link_cache)
59                 goto errout_put;
60
61         params.dp_type = nltool_parse_dumptype(argv[1]);
62         if (params.dp_type < 0)
63                 goto errout_put;
64
65         get_filter(link, argc, argv, 2, link_cache);
66         nl_cache_dump_filter(link_cache, &params, (struct nl_object *) link);
67         nl_cache_free(link_cache);
68         err = 0;
69 errout_put:
70         rtnl_link_put(link);
71 errout:
72         nl_close(nlh);
73         nl_handle_destroy(nlh);
74         return err;
75 }