12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/neigh.h> 14 #include <netlink/cli/link.h> 16 #include <linux/netlink.h> 20 static void print_usage(
void)
23 "Usage: nl-neigh-add [OPTION]... NEIGHBOUR\n" 26 " --update-only Do not create neighbour, updates exclusively\n" 27 " --create-only Do not update neighbour if it exists already.\n" 28 " -q, --quiet Do not print informal notifications\n" 29 " -h, --help Show this help\n" 30 " -v, --version Show versioning information\n" 33 " -a, --addr=ADDR Destination address of neighbour\n" 34 " -l, --lladdr=ADDR Link layer address of neighbour\n" 35 " -d, --dev=DEV Device the neighbour is connected to\n" 36 " --state=STATE Neighbour state, (default = permanent)\n" 39 " nl-neigh-add --create-only --addr=10.0.0.1 --dev=eth0 \\\n" 40 " --lladdr=AA:BB:CC:DD:EE:FF\n" 46 int main(
int argc,
char *argv[])
49 struct rtnl_neigh *neigh;
50 struct nl_cache *link_cache;
55 int err, ok = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
57 sock = nl_cli_alloc_socket();
58 nl_cli_connect(sock, NETLINK_ROUTE);
59 link_cache = nl_cli_link_alloc_cache(sock);
60 neigh = nl_cli_neigh_alloc();
65 ARG_UPDATE_ONLY = 257,
66 ARG_CREATE_ONLY = 258,
69 static struct option long_opts[] = {
70 {
"update-only", 0, 0, ARG_UPDATE_ONLY },
71 {
"create-only", 0, 0, ARG_CREATE_ONLY },
72 {
"quiet", 0, 0,
'q' },
73 {
"help", 0, 0,
'h' },
74 {
"version", 0, 0,
'v' },
75 {
"addr", 1, 0,
'a' },
76 {
"lladdr", 1, 0,
'l' },
78 {
"state", 1, 0, ARG_STATE },
82 c = getopt_long(argc, argv,
"qhva:l:d:", long_opts, &optidx);
87 case ARG_UPDATE_ONLY: nlflags &= ~NLM_F_CREATE;
break;
88 case ARG_CREATE_ONLY: nlflags |= NLM_F_EXCL;
break;
89 case 'q': quiet = 1;
break;
90 case 'h': print_usage();
break;
91 case 'v': nl_cli_print_version();
break;
92 case 'a': ok++; nl_cli_neigh_parse_dst(neigh, optarg);
break;
93 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg);
break;
94 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg);
break;
95 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg);
break;
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
int rtnl_neigh_add(struct nl_sock *sk, struct rtnl_neigh *tmpl, int flags)
Add a new neighbour.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.