12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/link.h>
15 static void print_usage(
void)
18 "Usage: nl-link-stats [OPTION]... [LINK] [ListOfStats]\n"
21 " -l, --list List available statistic names\n"
22 " -h, --help Show this help\n"
23 " -v, --version Show versioning information\n"
26 " -n, --name=NAME link name\n"
27 " -i, --index=NUM interface index\n"
32 static void list_stat_names(
void)
37 for (i = 0; i < RTNL_LINK_STATS_MAX; i++)
38 printf(
"%s\n", rtnl_link_stat2str(i, buf,
sizeof(buf)));
45 static void dump_stat(
struct rtnl_link *link,
int id)
51 rtnl_link_stat2str(
id, buf,
sizeof(buf)), st);
54 static void dump_stats(
struct nl_object *obj,
void *arg)
59 if (optind >= gargc) {
62 for (i = 0; i < RTNL_LINK_STATS_MAX; i++)
65 while (optind < gargc) {
66 int id = rtnl_link_str2stat(argv[optind]);
69 fprintf(stderr,
"Warning: Unknown statistic "
70 "\"%s\"\n", argv[optind]);
79 int main(
int argc,
char *argv[])
82 struct nl_cache *link_cache;
85 sock = nl_cli_alloc_socket();
86 nl_cli_connect(sock, NETLINK_ROUTE);
87 link_cache = nl_cli_link_alloc_cache(sock);
88 link = nl_cli_link_alloc();
92 static struct option long_opts[] = {
93 {
"list", 0, 0,
'l' },
94 {
"help", 0, 0,
'h' },
95 {
"version", 0, 0,
'v' },
96 {
"name", 1, 0,
'n' },
97 {
"index", 1, 0,
'i' },
101 c = getopt_long(argc, argv,
"lhvn:i:", long_opts, &optidx);
106 case 'l': list_stat_names();
break;
107 case 'h': print_usage();
break;
108 case 'v': nl_cli_print_version();
break;
109 case 'n': nl_cli_link_parse_name(link, optarg);
break;
110 case 'i': nl_cli_link_parse_ifindex(link, optarg);
break;