add packaging
[platform/upstream/libnl1.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 = nltool_alloc_handle();
30         if (!nlh)
31                 return -1;
32
33         neigh = rtnl_neigh_alloc();
34         if (neigh == NULL)
35                 goto errout;
36
37         if (nl_connect(nlh, NETLINK_ROUTE) < 0) {
38                 fprintf(stderr, "%s\n", nl_geterror());
39                 goto errout_free;
40         }
41
42         addr = nl_addr_parse(argv[1], AF_UNSPEC);
43         if (addr == NULL) {
44                 fprintf(stderr, "Invalid address \"%s\"\n", argv[1]);
45                 goto errout_close;
46         }
47         rtnl_neigh_set_dst(neigh, addr);
48         nl_addr_put(addr);
49
50         rtnl_neigh_set_ifindex(neigh, strtoul(argv[2], NULL, 0));
51
52         if (rtnl_neigh_delete(nlh, neigh, 0) < 0) {
53                 fprintf(stderr, "%s\n", nl_geterror());
54                 goto errout_close;
55         }
56
57         err = 0;
58
59 errout_close:
60         nl_close(nlh);
61 errout_free:
62         rtnl_neigh_put(neigh);
63 errout:
64         nl_handle_destroy(nlh);
65         return err;
66 }