nl-link-list.c revision d84430702496f617c01c5e2d27d0e82e02390bb7
1/*
2 * src/nl-link-dump.c	Dump link attributes
3 *
4 *	This library is free software; you can redistribute it and/or
5 *	modify it under the terms of the GNU Lesser General Public
6 *	License as published by the Free Software Foundation version 2.1
7 *	of the License.
8 *
9 * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
10 */
11
12#if 0
13static void print_usage(void)
14{
15	printf(
16	"Usage: nl-link-dump <mode> [<filter>]\n"
17	"  mode := { brief | detailed | stats | xml }\n"
18	"  filter := [dev DEV] [mtu MTU] [txqlen TXQLEN] [weight WEIGHT] [link LINK]\n"
19	"            [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n"
20	"            [{ up | down }] [{ arp | noarp }] [{ promisc | nopromisc }]\n"
21	"            [{ dynamic | nodynamic }] [{ multicast | nomulticast }]\n"
22	"            [{ trailers | notrailers }] [{ allmulticast | noallmulticast }]\n");
23	exit(1);
24}
25#endif
26
27#include "link-utils.h"
28
29static void print_usage(void)
30{
31	printf(
32	"Usage: nl-link-list [OPTION]... [Link]\n"
33	"\n"
34	"Options\n"
35	" -f, --format=TYPE     Output format { brief | details | stats }\n"
36	" -h, --help            Show this help\n"
37	" -v, --version         Show versioning information\n"
38	"\n"
39	"Link Options\n"
40	" -n, --name=NAME	link name\n"
41	" -i, --index           interface index\n"
42	"     --mtu=NUM         MTU value\n"
43	"     --txqlen=NUM      TX queue length\n"
44	"     --weight=NUM      weight\n"
45	);
46	exit(0);
47}
48
49int main(int argc, char *argv[])
50{
51	struct nl_sock *sock;
52	struct nl_cache *link_cache;
53	struct rtnl_link *link;
54	struct nl_dump_params params = {
55		.dp_type = NL_DUMP_LINE,
56		.dp_fd = stdout,
57	};
58
59	sock = nlt_alloc_socket();
60	nlt_connect(sock, NETLINK_ROUTE);
61	link_cache = nlt_alloc_link_cache(sock);
62	link = nlt_alloc_link();
63
64	for (;;) {
65		int c, optidx = 0;
66		enum {
67			ARG_FAMILY = 257,
68			ARG_MTU = 258,
69			ARG_TXQLEN,
70			ARG_WEIGHT,
71		};
72		static struct option long_opts[] = {
73			{ "format", 1, 0, 'f' },
74			{ "help", 0, 0, 'h' },
75			{ "version", 0, 0, 'v' },
76			{ "name", 1, 0, 'n' },
77			{ "index", 1, 0, 'i' },
78			{ "family", 1, 0, ARG_FAMILY },
79			{ "mtu", 1, 0, ARG_MTU },
80			{ "txqlen", 1, 0, ARG_TXQLEN },
81			{ "weight", 1, 0, ARG_WEIGHT },
82			{ 0, 0, 0, 0 }
83		};
84
85		c = getopt_long(argc, argv, "f:hvn:i:", long_opts, &optidx);
86		if (c == -1)
87			break;
88
89		switch (c) {
90		case 'f': params.dp_type = nlt_parse_dumptype(optarg); break;
91		case 'h': print_usage(); break;
92		case 'v': nlt_print_version(); break;
93		case 'n': parse_name(link, optarg); break;
94		case 'i': parse_ifindex(link, optarg); break;
95		case ARG_FAMILY: parse_family(link, optarg); break;
96		case ARG_MTU: parse_mtu(link, optarg); break;
97		case ARG_TXQLEN: parse_txqlen(link, optarg); break;
98		case ARG_WEIGHT: parse_weight(link, optarg); break;
99		}
100	}
101
102	nl_cache_dump_filter(link_cache, &params, OBJ_CAST(link));
103
104	return 0;
105}
106