13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/rule.h> 15 #include <netlink/cli/link.h> 17 #include <linux/netlink.h> 19 static void print_usage(
void)
22 "Usage: nl-rule-list [OPTION]... [ROUTE]\n" 25 " -c, --cache List the contents of the route cache\n" 26 " -f, --format=TYPE Output format { brief | details | stats }\n" 27 " -h, --help Show this help\n" 28 " -v, --version Show versioning information\n" 31 " --family Address family\n" 36 int main(
int argc,
char *argv[])
39 struct rtnl_rule *rule;
40 struct nl_cache *rule_cache;
46 sock = nl_cli_alloc_socket();
47 nl_cli_connect(sock, NETLINK_ROUTE);
48 nl_cli_link_alloc_cache(sock);
49 rule_cache = nl_cli_rule_alloc_cache(sock);
50 rule = nl_cli_rule_alloc();
57 static struct option long_opts[] = {
58 {
"format", 1, 0,
'f' },
59 {
"help", 0, 0,
'h' },
60 {
"version", 0, 0,
'v' },
61 {
"family", 1, 0, ARG_FAMILY },
65 c = getopt_long(argc, argv,
"f:hv", long_opts, &optidx);
70 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
71 case 'h': print_usage();
break;
72 case 'v': nl_cli_print_version();
break;
73 case ARG_FAMILY: nl_cli_rule_parse_family(rule, optarg);
break;
Dump object briefly on one line.
FILE * dp_fd
File descriptor the dumping output should go to.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
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).