12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/link.h> 15 #include <linux/netlink.h> 17 static void print_usage(
void)
20 "Usage: nl-link-list [OPTIONS]... \n" 23 " --details Show detailed information of each link\n" 24 " --stats Show statistics, implies --details\n" 25 " -h, --help Show this help text.\n" 26 " -v, --version Show versioning information.\n" 28 " -n, --name=NAME Name of link\n" 29 " -i, --index Interface index (unique identifier)\n" 30 " --family=NAME Link address family\n" 31 " --mtu=NUM MTU value\n" 32 " --txqlen=NUM TX queue length\n" 33 " --weight=NUM Weight\n" 38 int main(
int argc,
char *argv[])
41 struct nl_cache *link_cache;
48 sock = nl_cli_alloc_socket();
49 nl_cli_connect(sock, NETLINK_ROUTE);
50 link = nl_cli_link_alloc();
62 static struct option long_opts[] = {
63 {
"details", 0, 0, ARG_DETAILS },
64 {
"stats", 0, 0, ARG_STATS },
65 {
"help", 0, 0,
'h' },
66 {
"version", 0, 0,
'v' },
67 {
"name", 1, 0,
'n' },
68 {
"index", 1, 0,
'i' },
69 {
"family", 1, 0, ARG_FAMILY },
70 {
"mtu", 1, 0, ARG_MTU },
71 {
"txqlen", 1, 0, ARG_TXQLEN },
72 {
"weight", 1, 0, ARG_WEIGHT },
76 c = getopt_long(argc, argv,
"hvn:i:", long_opts, &optidx);
83 case 'h': print_usage();
break;
84 case 'v': nl_cli_print_version();
break;
85 case 'n': nl_cli_link_parse_name(link, optarg);
break;
86 case 'i': nl_cli_link_parse_ifindex(link, optarg);
break;
87 case ARG_FAMILY: nl_cli_link_parse_family(link, optarg);
break;
88 case ARG_MTU: nl_cli_link_parse_mtu(link, optarg);
break;
89 case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg);
break;
90 case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg);
break;
94 link_cache = nl_cli_link_alloc_cache_family(sock,
Dump object briefly on one line.
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).
Dump all attributes but no statistics.
int rtnl_link_get_family(struct rtnl_link *link)
Return address family of link object.
Dump all attributes including statistics.