nl-link-list.c revision d84430702496f617c01c5e2d27d0e82e02390bb7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * src/nl-link-dump.c Dump link attributes 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * This library is free software; you can redistribute it and/or 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * modify it under the terms of the GNU Lesser General Public 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * License as published by the Free Software Foundation version 2.1 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * of the License. 87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch * 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if 0 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static void print_usage(void) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){ 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) printf( 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Usage: nl-link-dump <mode> [<filter>]\n" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " mode := { brief | detailed | stats | xml }\n" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " filter := [dev DEV] [mtu MTU] [txqlen TXQLEN] [weight WEIGHT] [link LINK]\n" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) " [{ 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, ¶ms, OBJ_CAST(link)); 103 104 return 0; 105} 106