~ubuntu-branches/ubuntu/wily/ntop/wily-proposed

« back to all changes in this revision

Viewing changes to ntop/intop/dump.c

  • Committer: Bazaar Package Importer
  • Author(s): Dennis Schoen
  • Date: 2002-04-12 11:38:47 UTC
  • Revision ID: james.westby@ubuntu.com-20020412113847-4k4yydw0pzybc6g8
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
3
 * dump.c - Enable/Disable verbosity flags.
 
4
 *
 
5
 * Luca Deri     <deri@ntop.org>
 
6
 * Rocco Carbone <rocco@ntop.org>
 
7
 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
22
 */
 
23
 
 
24
 
 
25
/*
 
26
 * ntop header file(s)
 
27
 */
 
28
#include "ntop.h"
 
29
 
 
30
#include "intop.h"
 
31
 
 
32
 
 
33
 
 
34
/*
 
35
 * Get/Set Packets dump.
 
36
 */
 
37
int intop_dump (int argc, char * argv [])
 
38
{
 
39
  /*
 
40
   * Notice the command name.
 
41
   */
 
42
  char * commandname = argv [0];
 
43
 
 
44
  int c;
 
45
#define USAGE(xxx) \
 
46
  printf ("Usage: %s [-h] [-i interface] [-f filename] [-A] [-R] [-H] [-E] [-I] [-T]\n", xxx)
 
47
  char * optstring = "hi:f:ARHEIT";
 
48
 
 
49
  /*
 
50
   * Reserve here space for the local variables.
 
51
   */
 
52
  char * interface = NULL;
 
53
  int current;
 
54
  NtopInterface * n;
 
55
 
 
56
  static int hflag = 0;
 
57
  static int eflag = 0;
 
58
  static int iflag = 0;
 
59
  static int tflag = 0;
 
60
  static FILE * fd = NULL;
 
61
 
 
62
  optind = 0;
 
63
  optarg = NULL;
 
64
 
 
65
  /*
 
66
   * Parse command line options to the application via standard system calls.
 
67
   */
 
68
  while ((c = getopt (argc, argv, optstring)) != -1)
 
69
    {
 
70
      switch (c)
 
71
        {
 
72
        case 'h':
 
73
          USAGE (commandname);
 
74
          return (0);
 
75
 
 
76
        default:
 
77
          USAGE (commandname);
 
78
          return (-1);
 
79
 
 
80
        case 'i':
 
81
          interface = optarg;
 
82
          break;
 
83
 
 
84
        case 'f':
 
85
          if (! strcmp (optarg, "-"))
 
86
            fd = stdout;
 
87
          else
 
88
            {
 
89
              fd = fopen (optarg, "w");
 
90
              if (! fd)
 
91
                fprintf (stdout, "Cannot open %s.\n", optarg);
 
92
            }
 
93
          break;
 
94
 
 
95
        case 'R':
 
96
          fd = NULL;
 
97
          hflag = 0;
 
98
          eflag = 0;
 
99
          iflag = 0;
 
100
          tflag = 0;
 
101
          break;
 
102
 
 
103
        case 'A':
 
104
          if (! fd)
 
105
            fd = stdout;
 
106
          hflag = 1;
 
107
          eflag = 1;
 
108
          iflag = 1;
 
109
          tflag = 1;
 
110
          break;
 
111
 
 
112
        case 'H':
 
113
          if (! fd)
 
114
            fd = stdout;
 
115
          hflag = ! hflag;
 
116
          break;
 
117
 
 
118
        case 'E':
 
119
          if (! fd)
 
120
            fd = stdout;
 
121
          eflag = ! eflag;
 
122
          break;
 
123
 
 
124
        case 'I':
 
125
          if (! fd)
 
126
            fd = stdout;
 
127
          iflag = ! iflag;
 
128
          break;
 
129
 
 
130
        case 'T':
 
131
          if (! fd)
 
132
            fd = stdout;
 
133
          tflag = ! tflag;
 
134
          break;
 
135
        }
 
136
    }
 
137
 
 
138
  if (optind < argc)
 
139
    {
 
140
      printf ("\nWrong option(s): \" ");
 
141
      while (optind < argc)
 
142
        printf ("%s ", argv [optind ++]);
 
143
      printf ("\"\n");
 
144
      USAGE (commandname);
 
145
      printf ("\n");
 
146
      return (-1);
 
147
    }
 
148
 
 
149
  
 
150
  /*
 
151
   * Safe to play with the 'active' interface (if any)
 
152
   * in case no specific one was chosen by the user.
 
153
   */
 
154
  if (! interface && ! (interface = intop_interface (active)))
 
155
    {
 
156
      printf ("No interface is currently enabled for packet sniffing.\n");
 
157
      return (-1);
 
158
    }
 
159
 
 
160
  /*
 
161
   * Lookup for the given name in the table of enabled interfaces.
 
162
   */
 
163
  current = intop_lookup_interface (interface);
 
164
  if (current == -1)
 
165
    {
 
166
      printf ("%s: unknown interface %s.\n", commandname, interface);
 
167
      return (-1);
 
168
    }
 
169
 
 
170
  /*
 
171
   * Toogle the verbosity flags.
 
172
   */
 
173
  n = nethandler (current);
 
174
 
 
175
 
 
176
  n -> fdv     = fd;
 
177
  n -> hashing = hflag;
 
178
  n -> ethv    = eflag;
 
179
  n -> ipv     = iflag;
 
180
  n -> tcpv    = tflag;;
 
181
 
 
182
  return (0);
 
183
}