source: rtems/cpukit/libmisc/shell/main_netstats.c @ dedb9229

4.9
Last change on this file since dedb9229 was dedb9229, checked in by Joel Sherrill <joel.sherrill@…>, on 12/02/08 at 18:50:43

2008-12-02 Joel Sherrill <joel.sherrill@…>

  • libmisc/shell/main_cp.c, libmisc/shell/main_ls.c, libmisc/shell/main_mv.c, libmisc/shell/main_netstats.c, libmisc/shell/main_rm.c, libmisc/shell/shell_script.c: Add #define need_getopt_newlib to enable getopt_r() support in newlib as required by 4.10 toolset.
  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 *  Network Statistics Shell Command Implmentation
3 *
4 *  COPYRIGHT (c) 1989-2008.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <stdio.h>
19#define __need_getopt_newlib
20#include <getopt.h>
21
22#include <rtems.h>
23#include <rtems/rtems_bsdnet.h>
24#include <rtems/shell.h>
25#include "internal.h"
26
27static void netstats_usage(void)
28{
29  printf(
30    "netstats [-vAimfpcut] where:\n"
31    "  -A    print All statistics\n"
32    "  -i    print Inet Routes\n"
33    "  -m    print MBUF Statistics\n"
34    "  -f    print IF Statistics\n"
35    "  -p    print IP Statistics\n"
36    "  -c    print ICMP Statistics\n"
37    "  -u    print UDP Statistics\n"
38    "  -t    print TCP Statistics\n"
39  );
40}
41
42int rtems_shell_main_netstats(                       /* command */
43  int   argc,
44  char *argv[]
45)
46{
47  int   option;
48  int   doAll = 0;
49  int   doInetRoutes = 0;
50  int   doMBUFStats = 0;
51  int   doIFStats = 0;
52  int   doIPStats = 0;
53  int   doICMPStats = 0;
54  int   doUDPStats = 0;
55  int   doTCPStats = 0;
56  int   verbose = 0;
57  struct getopt_data getopt_reent;
58
59  memset(&getopt_reent, 0, sizeof(getopt_data));
60  while ( (option = getopt_r( argc, argv, "Aimfpcutv", &getopt_reent)) != -1 ) {
61
62    switch ((char)option) {
63      case 'A': doAll = 1;        break;
64      case 'i': doInetRoutes = 1; break;
65      case 'm': doMBUFStats = 1;  break;
66      case 'f': doIFStats = 1;    break;
67      case 'p': doIPStats = 1;    break;
68      case 'c': doICMPStats = 1;  break;
69      case 'u': doUDPStats = 1;   break;
70      case 't': doTCPStats = 1;   break;
71      case 'v': verbose = 1;      break;
72      case '?':
73      default:
74        netstats_usage();
75        return -1;
76    }
77  }
78 
79  if ( verbose ) {
80    printf(
81      "doAll=%d\n"
82      "doInetRoutes=%d\n"
83      "doMBUFStats=%d\n"
84      "doIFStats=%d\n"
85      "doIPStats=%d\n"
86      "doICMPStats=%d\n"
87      "doUDPStats=%d\n"
88      "doTCPStats=%d\n",
89      doAll,
90      doInetRoutes,
91      doMBUFStats,
92      doIFStats,
93      doIPStats,
94      doICMPStats,
95      doUDPStats,
96      doTCPStats
97    );
98  }
99
100#if 0
101  if ( doInetRoutes == 1 || doAll == 1 ) {
102    rtems_bsdnet_show_inet_routes();
103  }
104
105  if ( doMBUFStats == 1 || doAll == 1 ) {
106    rtems_bsdnet_show_mbuf_stats();
107  }
108
109  if ( doIFStats == 1 || doAll == 1 ) {
110    rtems_bsdnet_show_if_stats();
111  }
112
113  if ( doIPStats == 1 || doAll == 1 ) {
114    rtems_bsdnet_show_ip_stats();
115  }
116
117  if ( doICMPStats == 1 || doAll == 1 ) {
118    rtems_bsdnet_show_icmp_stats();
119  }
120
121  if ( doUDPStats == 1 || doAll == 1 ) {
122    rtems_bsdnet_show_udp_stats();
123  }
124
125  if ( doTCPStats == 1 || doAll == 1 ) {
126    rtems_bsdnet_show_tcp_stats();
127  }
128
129#endif
130  return 0;
131}
132
133rtems_shell_cmd_t rtems_shell_NETSTATS_Command = {
134  "netstats",                                      /* name */
135  "netstats [-Aimfpcutv]",                         /* usage */
136  "network",                                       /* topic */
137  rtems_shell_main_netstats,                       /* command */
138  NULL,                                            /* alias */
139  NULL                                             /* next */
140};
Note: See TracBrowser for help on using the repository browser.