oops
[libnl.git] / src / nl-addr-delete.c
1 /*
2  * src/nl-addr-delete.c     Delete addresses
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 int main(int argc, char *argv[])
15 {
16         struct nl_handle *nlh;
17         struct rtnl_addr *addr;
18         struct nl_addr *local;
19         int err = 1;
20
21         if (argc < 3 || !strcmp(argv[1], "-h")) {
22                 printf("Usage: nl-addr-delete <addr> <ifindex>\n");
23                 goto errout;
24         }
25
26         if (nltool_init(argc, argv) < 0)
27                 goto errout;
28
29         nlh = nl_handle_alloc_nondefault(nltool_cbset);
30         if (!nlh)
31                 goto errout;
32
33         addr = rtnl_addr_alloc();
34         if (!addr)
35                 goto errout_free_handle;
36
37         if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
38                 goto errout_free_addr;
39
40         local = nltool_addr_parse(argv[1]);
41         if (!local)
42                 goto errout_close;
43
44         if (rtnl_addr_set_local(addr, local) < 0) {
45                 fprintf(stderr, "Unable to set local address: %s\n",
46                         nl_geterror());
47                 goto errout_addr_put;
48         }
49
50         rtnl_addr_set_ifindex(addr, strtoul(argv[2], NULL, 0));
51
52         if (rtnl_addr_delete(nlh, addr, 0) < 0) {
53                 fprintf(stderr, "Unable to delete address: %s\n",
54                         nl_geterror());
55                 goto errout_addr_put;
56         }
57
58         err = 0;
59
60 errout_addr_put:
61         nl_addr_put(local);
62 errout_close:
63         nl_close(nlh);
64 errout_free_addr:
65         rtnl_addr_put(addr);
66 errout_free_handle:
67         nl_handle_destroy(nlh);
68 errout:
69         return err;
70 }