~ubuntu-branches/ubuntu/natty/ntop/natty

« back to all changes in this revision

Viewing changes to ntop/intop/info.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-01-30 21:59:13 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050130215913-xc3ke963bw49b3k4
Tags: 2:3.0-5
* Updated README.Debian file so users will understand what to do at
  install, closes: #291794, #287802.
* Updated ntop init script to give better output.
* Also changed log directory from /var/lib/ntop to /var/log/ntop,
  closes: #252352.
* Quoted the interface list to allow whitespace, closes: #267248.
* Added a couple of logcheck ignores, closes: #269321, #269319.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
3
 
 * info.c - Display detailed about the actual state of a network interface.
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
 
 * Print current network interface information
34
 
 * in a format readable for humans.
35
 
 */
36
 
int intop_info (int argc, char * argv [])
37
 
{
38
 
  /*
39
 
   * Notice the command name.
40
 
   */
41
 
  char * commandname = argv [0];
42
 
 
43
 
  int c;
44
 
#define USAGE(xxx) \
45
 
  printf ("Usage: %s [-h]\n\
46
 
           [-i interface]\n", xxx)
47
 
  char * optstring = "hi:";
48
 
 
49
 
  /*
50
 
   * Reserve here space for the local variables.
51
 
   */
52
 
  char * interface = NULL;
53
 
  int current;
54
 
  NtopInterface * n;
55
 
  time_t now = NOW;
56
 
 
57
 
  optind = 0;
58
 
  optarg = NULL;
59
 
 
60
 
  /*
61
 
   * Parse command line options to the application via standard system calls.
62
 
   */
63
 
  while ((c = getopt (argc, argv, optstring)) != -1)
64
 
    {
65
 
      switch (c)
66
 
        {
67
 
        case 'h':
68
 
          USAGE (commandname);
69
 
          return (0);
70
 
 
71
 
        default:
72
 
          USAGE (commandname);
73
 
          return (-1);
74
 
 
75
 
        case 'i':
76
 
          interface = optarg;
77
 
          break;
78
 
        }
79
 
    }
80
 
 
81
 
  if (optind < argc)
82
 
    {
83
 
      printf ("\nWrong option(s): \" ");
84
 
      while (optind < argc)
85
 
        printf ("%s ", argv [optind ++]);
86
 
      printf ("\"\n");
87
 
      USAGE (commandname);
88
 
      printf ("\n");
89
 
      return (-1);
90
 
    }
91
 
 
92
 
  /*
93
 
   * Safe to play with the 'active' interface (if any)
94
 
   * in case no specific one was chosen by the user.
95
 
   */
96
 
  if (! interface && ! (interface = intop_interface (active)))
97
 
    {
98
 
      printf ("No interface is currently enabled for packet sniffing.\n");
99
 
      return (-1);
100
 
    }
101
 
 
102
 
  /*
103
 
   * Lookup for the given name in the table of enabled interfaces.
104
 
   */
105
 
  current = intop_lookup_interface (interface);
106
 
  if (current == -1)
107
 
    {
108
 
      printf ("%s: unknown interface %s.\n", commandname, interface);
109
 
      return (-1);
110
 
    }
111
 
 
112
 
  /*
113
 
   * General information about the interface.
114
 
   */
115
 
 
116
 
  n = nethandler (current);
117
 
 
118
 
  {
119
 
    char * fqdn = intop_iphuman (current);
120
 
 
121
 
    if (strchr (fqdn, '.'))
122
 
      printf ("Network interface: %s [%s] %s [%s] set to %s mode\n",
123
 
              interface, intop_dltype (current),
124
 
              fqdn, intop_ipdot (current),
125
 
              get_intop_flags (current) == INTERFACE_READY ? "non promiscuous" : "promiscuous");
126
 
    else
127
 
      printf ("Network interface: %s [%s] %s.%s [%s] set to %s mode\n",
128
 
              interface, intop_dltype (current),
129
 
              fqdn, domainName, intop_ipdot (current),
130
 
              get_intop_flags (current) == INTERFACE_READY ? "non promiscuous" : "promiscuous");
131
 
  }
132
 
 
133
 
 
134
 
  printf ("Sampling since    :  [%s] %s", formatSeconds (now - n -> started), ctime (& n -> started));
135
 
  printf ("\n");
136
 
 
137
 
  printf ("Packets:\n");
138
 
  printf ("  Received           : %s\n", cformatPkts (receivedpkts (current)));
139
 
  printf ("  Dropped by program : %s\n", cformatPkts (droppedpkts (current)));
140
 
  printf ("  Dropped by kernel  : %s\n", cformatPkts (kerneldroppedpkts (current)));
141
 
 
142
 
  printf ("  Ethernet           : %s\n", cformatPkts (ethpkts (current)));
143
 
  printf ("    Unicast          : %s\n",
144
 
          cformatPkts (ethpkts (current) - broadcastpkts (current) - multicastpkts (current)));
145
 
  printf ("    Broadcast        : %s\n", cformatPkts (broadcastpkts (current)));
146
 
  printf ("    Multicast        : %s\n", cformatPkts (multicastpkts (current)));
147
 
 
148
 
 
149
 
  printf ("\n");
150
 
 
151
 
  printf ("Bytes:\n");
152
 
  printf ("  Total              : %s\n", cformatBytes (ethbytes (current)));
153
 
  printf ("   IP                : %s\n", cformatBytes (ipbytes (current)));
154
 
  printf ("   TCP               : %s\n", cformatBytes (tcpbytes (current)));
155
 
  printf ("   UDP               : %s\n", cformatBytes (udpbytes (current)));
156
 
  printf ("   Other IP          : %s\n", cformatBytes (otheripbytes (current)));
157
 
  printf ("     ICMP            : %s\n", cformatBytes (icmpbytes (current)));
158
 
  printf ("     NetBIOS         : %s\n", cformatBytes (netbiosbytes (current)));
159
 
  printf ("     r(ARP)          : %s\n", cformatBytes (arpbytes (current)));
160
 
  printf ("     AppleTalk       : %s\n", cformatBytes (appletalkbytes (current)));
161
 
  printf ("     IPX             : %s\n", cformatBytes (ipxbytes (current)));
162
 
  printf ("     DecNET          : %s\n", cformatBytes (decnetbytes (current)));
163
 
  printf ("     DLC             : %s\n", cformatBytes (dlcbytes (current)));
164
 
  printf ("     OSPF            : %s\n", cformatBytes (ospfbytes (current)));
165
 
  printf ("     EGP             : %s\n", cformatBytes (egpbytes (current)));
166
 
  printf ("     IGMP            : %s\n", cformatBytes (igmpbytes (current)));
167
 
  printf ("     OSI             : %s\n", cformatBytes (osibytes (current)));
168
 
  printf ("     QNX             : %s\n", cformatBytes (qnxbytes (current)));
169
 
  printf ("     Other           : %s\n", cformatBytes (otherbytes (current)));
170
 
 
171
 
  printf ("\n");
172
 
 
173
 
  fflush (stdout);
174
 
 
175
 
  return (0);
176
 
}