This commit was generated by cvs2svn to compensate for changes in r786,
[libnl.git] / src / nl-addr-dump.c
1 /*
2  * src/nl-addr-dump.c     Dump address 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-addr-dump <mode> [<filter>]\n"
18         "  mode := { brief | detailed | stats | xml }\n"
19         "  filter := [dev DEV] [label LABEL] [family FAMILY] [scope SCOPE]\n"
20         "            [local ADDR] [peer ADDR] [broadcast ADDR] [anycast ADDR]\n"
21         "            [multicast ADDR]\n");
22         exit(1);
23 }
24
25 #include "f_addr.c"
26
27 int main(int argc, char *argv[])
28 {
29         struct nl_handle *nlh;
30         struct nl_cache *link_cache, *addr_cache;
31         struct rtnl_addr *addr;
32         struct nl_dump_params params = {
33                 .dp_fd = stdout,
34                 .dp_type = NL_DUMP_BRIEF
35         };
36         int err = 1;
37
38         if (nltool_init(argc, argv) < 0)
39                 return -1;
40
41         nlh = nl_handle_alloc_nondefault(nltool_cbset);
42         if (!nlh)
43                 return -1;
44
45         addr = rtnl_addr_alloc();
46         if (!addr)
47                 goto errout;
48
49         if (argc < 2 || !strcmp(argv[1], "-h"))
50                 print_usage();
51
52         if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
53                 goto errout_free;
54
55         link_cache = nltool_alloc_link_cache(nlh);
56         if (!link_cache)
57                 goto errout_close;
58
59         addr_cache = nltool_alloc_addr_cache(nlh);
60         if (!addr_cache)
61                 goto errout_link_cache;
62
63         params.dp_type = nltool_parse_dumptype(argv[1]);
64         if (params.dp_type < 0)
65                 goto errout_addr_cache;
66         get_filter(addr, argc, argv, 2, link_cache);
67
68         nl_cache_dump_filter(addr_cache, &params, (struct nl_object *) addr);
69
70         err = 0;
71
72 errout_addr_cache:
73         nl_cache_free(addr_cache);
74 errout_link_cache:
75         nl_cache_free(link_cache);
76 errout_close:
77         nl_close(nlh);
78 errout_free:
79         rtnl_addr_put(addr);
80 errout:
81         return err;
82 }