6#include <netlink/cli/utils.h>
7#include <netlink/cli/neigh.h>
8#include <netlink/cli/link.h>
10#include <linux/netlink.h>
12static void print_usage(
void)
15 "Usage: nl-neigh-list [OPTION]... [NEIGHBOUR]\n"
18 " -f, --format=TYPE Output format { brief | details | stats }\n"
19 " -h, --help Show this help\n"
20 " -v, --version Show versioning information\n"
23 " -a, --addr=ADDR Destination address of neighbour\n"
24 " -l, --lladdr=ADDR Link layer address of neighbour\n"
25 " -d, --dev=DEV Device the neighbour is connected to\n"
26 " --family=FAMILY Destination address family\n"
27 " --state=STATE Neighbour state, (default = permanent)\n"
32int main(
int argc,
char *argv[])
35 struct rtnl_neigh *neigh;
36 struct nl_cache *link_cache, *neigh_cache;
42 sock = nl_cli_alloc_socket();
43 nl_cli_connect(sock, NETLINK_ROUTE);
45 neigh_cache = nl_cli_neigh_alloc_cache(sock);
46 neigh = nl_cli_neigh_alloc();
54 static struct option long_opts[] = {
55 {
"format", 1, 0,
'f' },
56 {
"help", 0, 0,
'h' },
57 {
"version", 0, 0,
'v' },
58 {
"addr", 1, 0,
'a' },
59 {
"lladdr", 1, 0,
'l' },
61 {
"family", 1, 0, ARG_FAMILY },
62 {
"state", 1, 0, ARG_STATE },
66 c = getopt_long(argc, argv,
"f:hva:l:d:", long_opts, &optidx);
71 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
72 case 'h': print_usage();
break;
73 case 'v': nl_cli_print_version();
break;
74 case 'a': nl_cli_neigh_parse_dst(neigh, optarg);
break;
75 case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg);
break;
76 case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg);
break;
77 case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg);
break;
78 case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg);
break;
84 rtnl_neigh_put(neigh);
85 nl_cache_put(neigh_cache);
86 nl_cache_put(link_cache);
void nl_cache_dump_filter(struct nl_cache *cache, struct nl_dump_params *params, struct nl_object *filter)
Dump all elements of a cache (filtered).
#define NL_CACHE_AF_ITER
Explicitely iterate over all address families when updating the cache.
void nl_socket_free(struct nl_sock *sk)
Free a netlink socket.
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.