2 * src/ nl-neigh-add.c Add a neighbour
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
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
14 int main(int argc, char *argv[])
16 struct nl_handle *nlh;
17 struct rtnl_neigh *neigh;
21 if (nltool_init(argc, argv) < 0)
24 if (argc < 4 || !strcmp(argv[1], "-h")) {
25 printf("Usage: nl-neigh-add <addr> <lladdr> "
26 "<ifindex> [<state>]\n");
30 nlh = nl_handle_alloc_nondefault(nltool_cbset);
34 neigh = rtnl_neigh_alloc();
38 if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
41 addr = nltool_addr_parse(argv[1]);
44 rtnl_neigh_set_dst(neigh, addr);
47 addr = nltool_addr_parse(argv[2]);
50 rtnl_neigh_set_lladdr(neigh, addr);
53 rtnl_neigh_set_ifindex(neigh, strtoul(argv[3], NULL, 0));
56 int state = rtnl_neigh_str2state(argv[4]);
58 fprintf(stderr, "Unknown state \"%s\"\n", argv[4]);
61 rtnl_neigh_set_state(neigh, state);
63 rtnl_neigh_set_state(neigh, NUD_PERMANENT);
65 if (rtnl_neigh_add(nlh, neigh, 0) < 0) {
66 fprintf(stderr, "Unable to add address: %s\n", nl_geterror());
75 rtnl_neigh_put(neigh);
77 nl_handle_destroy(nlh);