8#include <linux/netlink.h>
10#include <netlink/cli/utils.h>
11#include <netlink/cli/rule.h>
12#include <netlink/cli/link.h>
14static void print_usage(
void)
17 "Usage: nl-rule-list [OPTION]... [ROUTE]\n"
20 " -c, --cache List the contents of the route cache\n"
21 " -f, --format=TYPE Output format { brief | details | stats }\n"
22 " -h, --help Show this help\n"
23 " -v, --version Show versioning information\n"
26 " --family Address family\n"
31int main(
int argc,
char *argv[])
34 struct rtnl_rule *rule;
35 struct nl_cache *rule_cache;
41 sock = nl_cli_alloc_socket();
42 nl_cli_connect(sock, NETLINK_ROUTE);
43 nl_cli_link_alloc_cache(sock);
44 rule_cache = nl_cli_rule_alloc_cache(sock);
45 rule = nl_cli_rule_alloc();
52 static struct option long_opts[] = {
53 {
"format", 1, 0,
'f' },
54 {
"help", 0, 0,
'h' },
55 {
"version", 0, 0,
'v' },
56 {
"family", 1, 0, ARG_FAMILY },
60 c = getopt_long(argc, argv,
"f:hv", long_opts, &optidx);
65 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
66 case 'h': print_usage();
break;
67 case 'v': nl_cli_print_version();
break;
68 case ARG_FAMILY: nl_cli_rule_parse_family(rule, optarg);
break;
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).
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
FILE * dp_fd
File descriptor the dumping output should go to.