8#include <linux/netlink.h>
10#include <netlink/cli/utils.h>
11#include <netlink/cli/link.h>
13static void print_usage(
void)
16"Usage: nl-link-list [OPTIONS]... \n"
19" --details Show detailed information of each link\n"
20" --stats Show statistics, implies --details\n"
21" -h, --help Show this help text.\n"
22" -v, --version Show versioning information.\n"
24" -n, --name=NAME Name of link\n"
25" -i, --index Interface index (unique identifier)\n"
26" --family=NAME Link address family\n"
27" --mtu=NUM MTU value\n"
28" --txqlen=NUM TX queue length\n"
29" --weight=NUM Weight\n"
34int main(
int argc,
char *argv[])
37 struct nl_cache *link_cache;
44 sock = nl_cli_alloc_socket();
45 nl_cli_connect(sock, NETLINK_ROUTE);
46 link = nl_cli_link_alloc();
58 static struct option long_opts[] = {
59 {
"details", 0, 0, ARG_DETAILS },
60 {
"stats", 0, 0, ARG_STATS },
61 {
"help", 0, 0,
'h' },
62 {
"version", 0, 0,
'v' },
63 {
"name", 1, 0,
'n' },
64 {
"index", 1, 0,
'i' },
65 {
"family", 1, 0, ARG_FAMILY },
66 {
"mtu", 1, 0, ARG_MTU },
67 {
"txqlen", 1, 0, ARG_TXQLEN },
68 {
"weight", 1, 0, ARG_WEIGHT },
72 c = getopt_long(argc, argv,
"hvn:i:", long_opts, &optidx);
79 case 'h': print_usage();
break;
80 case 'v': nl_cli_print_version();
break;
81 case 'n': nl_cli_link_parse_name(link, optarg);
break;
82 case 'i': nl_cli_link_parse_ifindex(link, optarg);
break;
83 case ARG_FAMILY: nl_cli_link_parse_family(link, optarg);
break;
84 case ARG_MTU: nl_cli_link_parse_mtu(link, optarg);
break;
85 case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg);
break;
86 case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg);
break;
90 link_cache = nl_cli_link_alloc_cache_family(sock,
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).
int rtnl_link_get_family(struct rtnl_link *link)
Return address family of link object.
@ NL_DUMP_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.