nl-neightbl-list.c revision d84430702496f617c01c5e2d27d0e82e02390bb7
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-2008 Thomas Graf <tgraf@suug.ch> 10 */ 11 12#include "utils.h" 13 14static void print_usage(void) 15{ 16 printf( 17 "Usage: nl-neightbl-list [OPTION]...\n" 18 "\n" 19 "Options\n" 20 " -f, --format=TYPE Output format { brief | details | stats }\n" 21 " -h, --help Show this help\n" 22 " -v, --version Show versioning information\n" 23 ); 24 exit(0); 25} 26 27int main(int argc, char *argv[]) 28{ 29 struct nl_sock *sock; 30 struct nl_cache *link_cache, *neightbl_cache; 31 struct nl_dump_params params = { 32 .dp_type = NL_DUMP_LINE, 33 .dp_fd = stdout, 34 }; 35 36 sock = nlt_alloc_socket(); 37 nlt_connect(sock, NETLINK_ROUTE); 38 link_cache = nlt_alloc_link_cache(sock); 39 neightbl_cache = nlt_alloc_neightbl_cache(sock); 40 41 for (;;) { 42 int c, optidx = 0; 43 static struct option long_opts[] = { 44 { "format", 1, 0, 'f' }, 45 { "help", 0, 0, 'h' }, 46 { "version", 0, 0, 'v' }, 47 { 0, 0, 0, 0 } 48 }; 49 50 c = getopt_long(argc, argv, "f:hv", long_opts, &optidx); 51 if (c == -1) 52 break; 53 54 switch (c) { 55 case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; 56 case 'h': print_usage(); break; 57 case 'v': nlt_print_version(); break; 58 } 59 } 60 61 nl_cache_dump(neightbl_cache, ¶ms); 62 63 return 0; 64} 65