Home | History | Annotate | Download | only in src
      1 /*
      2  * src/nl-neightbl-list.c     Dump neighbour tables
      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-2009 Thomas Graf <tgraf (at) suug.ch>
     10  */
     11 
     12 #include <netlink/cli/utils.h>
     13 #include <netlink/cli/link.h>
     14 
     15 static void print_usage(void)
     16 {
     17 	printf(
     18 	"Usage: nl-neightbl-list [OPTION]...\n"
     19 	"\n"
     20 	"Options\n"
     21 	" -f, --format=TYPE     Output format { brief | details | stats }\n"
     22 	" -h, --help            Show this help\n"
     23 	" -v, --version         Show versioning information\n"
     24 	);
     25 	exit(0);
     26 }
     27 
     28 int main(int argc, char *argv[])
     29 {
     30 	struct nl_sock *sock;
     31 	struct nl_cache *link_cache, *neightbl_cache;
     32 	struct nl_dump_params params = {
     33 		.dp_type = NL_DUMP_LINE,
     34 		.dp_fd = stdout,
     35 	};
     36 
     37 	sock = nl_cli_alloc_socket();
     38 	nl_cli_connect(sock, NETLINK_ROUTE);
     39 	link_cache = nl_cli_link_alloc_cache(sock);
     40 	neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table",
     41 					    rtnl_neightbl_alloc_cache);
     42 
     43 	for (;;) {
     44 		int c, optidx = 0;
     45 		static struct option long_opts[] = {
     46 			{ "format", 1, 0, 'f' },
     47 			{ "help", 0, 0, 'h' },
     48 			{ "version", 0, 0, 'v' },
     49 			{ 0, 0, 0, 0 }
     50 		};
     51 
     52 		c = getopt_long(argc, argv, "f:hv", long_opts, &optidx);
     53 		if (c == -1)
     54 			break;
     55 
     56 		switch (c) {
     57 		case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
     58 		case 'h': print_usage(); break;
     59 		case 'v': nl_cli_print_version(); break;
     60 		}
     61  	}
     62 
     63 	nl_cache_dump(neightbl_cache, &params);
     64 
     65 	return 0;
     66 }
     67