This commit is contained in:
chris
2002-04-01 22:03:49 +00:00
parent 57afc62a3a
commit e7c96c16cc
4 changed files with 24 additions and 15 deletions

View File

@@ -65,11 +65,9 @@ tags :
etags *.c *.h etags *.c *.h
depend: $(SRCS) depend: $(SRCS)
$(CPP) -MM $(SRCS) > depend $(CPP) $(CFLAGS) -MM $(SRCS) > depend
nodepend: nodepend:
rm -f depend rm -f depend
include depend include depend

View File

@@ -11,7 +11,7 @@ iftop - display bandwidth usage on an interface by host
.SH SYNOPSIS .SH SYNOPSIS
\fBiftop\fP \fB-h\fP | \fBiftop\fP \fB-h\fP |
[\fB-d\fP] [\fB-p\fP] [\fB-i\fP \fIinterface\fP] [\fB-f\fP \fIfilter code\fP] [\fB-d\fP] [\fB-p\fP] [\fB-i\fP \fIinterface\fP] [\fB-f\fP \fIfilter code\fP] [\fB-n\fP \fInet\fP/\fImask\fP]
.SH DESCRIPTION .SH DESCRIPTION
\fBiftop\fP listens to network traffic on a named \fIinterface\fP, or \fBeth0\fP \fBiftop\fP listens to network traffic on a named \fIinterface\fP, or \fBeth0\fP
@@ -68,7 +68,7 @@ Listen to packets on \fIinterface\fP.
Use \fIfilter code\fP to select the packets to count. Only IP packets are ever Use \fIfilter code\fP to select the packets to count. Only IP packets are ever
counted, so the specified code is evaluated as \fB(\fP\fIfilter code\fP\fB) and ip\fP. counted, so the specified code is evaluated as \fB(\fP\fIfilter code\fP\fB) and ip\fP.
.TP .TP
\fB-n\fP \fInet/mask\fP \fB-n\fP \fInet\fP/\fImask\fP
Specifies a network for traffic analysis. If specified, iftop will only Specifies a network for traffic analysis. If specified, iftop will only
include packets flowing in to or out of the given network, and packet direction include packets flowing in to or out of the given network, and packet direction
is determined relative to the network boundary, rather than to the interface. is determined relative to the network boundary, rather than to the interface.

View File

@@ -15,6 +15,7 @@
#include <curses.h> #include <curses.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "iftop.h" #include "iftop.h"
#include "addr_hash.h" #include "addr_hash.h"

View File

@@ -7,6 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include "options.h" #include "options.h"
@@ -35,18 +36,27 @@ void die(char *msg) {
void set_net_filter(char* arg) { void set_net_filter(char* arg) {
char* mask; char* mask;
mask = strstr(arg, "/"); mask = strchr(arg, '/');
if(mask == NULL) { if (mask == NULL) {
die("Could not parse net/mask\n"); die("Could not parse net/mask\n");
} }
*mask = '\0'; *mask = '\0';
mask++; mask++;
if(inet_aton(arg, &options.netfilternet) == 0) { if (inet_aton(arg, &options.netfilternet) == 0)
die("Invalid network address\n"); die("Invalid network address\n");
/* Accept a netmask like /24 or /255.255.255.0. */
if (!mask[strspn(mask, "0123456789")]) {
int n;
n = atoi(mask);
if (n > 32)
die("Invalid netmask");
else {
uint32_t mm = 0xffffffffl;
mm >>= n;
options.netfiltermask.s_addr = htonl(~mm);
} }
if(inet_aton(mask, &options.netfiltermask) == 0) { } else if (inet_aton(mask, &options.netfiltermask) == 0)
die("Invalid network mask\n"); die("Invalid netmask\n");
}
options.netfilter = 1; options.netfilter = 1;
@@ -58,7 +68,7 @@ void usage(FILE *fp) {
fprintf(fp, fprintf(fp,
"iftop: display bandwidth usage on an interface by host\n" "iftop: display bandwidth usage on an interface by host\n"
"\n" "\n"
"Synopsis: iftop -h | [-d] [-p] [-i interface] [-f filter code]\n" "Synopsis: iftop -h | [-d] [-p] [-i interface] [-f filter code] [-n net/mask]\n"
"\n" "\n"
" -h display this message\n" " -h display this message\n"
" -d don't do hostname lookups\n" " -d don't do hostname lookups\n"
@@ -69,7 +79,7 @@ void usage(FILE *fp) {
" (default: none, but only IP packets are counted)\n" " (default: none, but only IP packets are counted)\n"
" -n network/netmask show traffic flows in/out of network\n" " -n network/netmask show traffic flows in/out of network\n"
"\n" "\n"
"iftop, version " IFTOP_VERSION "copyright (c) 2002 Paul Warren <pdw@ex-parrot.com>\n" "iftop, version " IFTOP_VERSION " copyright (c) 2002 Paul Warren <pdw@ex-parrot.com>\n"
); );
} }