oops
[libnl.git] / src / nl-neigh-delete.c
1 /*
2  * src/nl-neigh-delete.c     Delete a neighbour
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_neigh *neigh;
18         struct nl_addr *addr;
19         int err = 1;
20
21         if (nltool_init(argc, argv) < 0)
22                 return -1;
23
24         if (argc < 3 || !strcmp(argv[1], "-h")) {
25                 printf("Usage: nl-neigh-delete <addr> <ifindex>\n");
26                 return 2;
27         }
28
29         nlh = nl_handle_alloc_nondefault(nltool_cbset);
30
31         neigh = rtnl_neigh_alloc();
32         if (neigh == NULL)
33                 goto errout;
34
35         if (nl_connect(nlh, NETLINK_ROUTE) < 0) {
36                 fprintf(stderr, "%s\n", nl_geterror());
37                 goto errout_free;
38         }
39
40         addr = nl_addr_parse(argv[1], AF_UNSPEC);
41         if (addr == NULL) {
42                 fprintf(stderr, "Invalid address \"%s\"\n", argv[1]);
43                 goto errout_close;
44         }
45         rtnl_neigh_set_dst(neigh, addr);
46         nl_addr_put(addr);
47
48         rtnl_neigh_set_ifindex(neigh, strtoul(argv[2], NULL, 0));
49
50         if (rtnl_neigh_delete(nlh, neigh, 0) < 0) {
51                 fprintf(stderr, "%s\n", nl_geterror());
52                 goto errout_close;
53         }
54
55         err = 0;
56
57 errout_close:
58         nl_close(nlh);
59 errout_free:
60         rtnl_neigh_put(neigh);
61 errout:
62         nl_handle_destroy(nlh);
63         return err;
64 }