From e7c96c16cc69064b5ae42ec6e255d9b09aebcf76 Mon Sep 17 00:00:00 2001 From: chris <> Date: Mon, 1 Apr 2002 22:03:49 +0000 Subject: [PATCH] "" --- Makefile | 6 ++---- iftop.8 | 4 ++-- iftop.c | 1 + options.c | 28 +++++++++++++++++++--------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index ed11a80..52581ca 100644 --- a/Makefile +++ b/Makefile @@ -65,11 +65,9 @@ tags : etags *.c *.h depend: $(SRCS) - $(CPP) -MM $(SRCS) > depend + $(CPP) $(CFLAGS) -MM $(SRCS) > depend nodepend: rm -f depend - + include depend - - diff --git a/iftop.8 b/iftop.8 index b750344..684e52b 100644 --- a/iftop.8 +++ b/iftop.8 @@ -11,7 +11,7 @@ iftop - display bandwidth usage on an interface by host .SH SYNOPSIS \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 \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 counted, so the specified code is evaluated as \fB(\fP\fIfilter code\fP\fB) and ip\fP. .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 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. diff --git a/iftop.c b/iftop.c index 81e36fd..bb645e8 100644 --- a/iftop.c +++ b/iftop.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "iftop.h" #include "addr_hash.h" diff --git a/options.c b/options.c index 3fd5edc..2363b81 100644 --- a/options.c +++ b/options.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "options.h" @@ -35,18 +36,27 @@ void die(char *msg) { void set_net_filter(char* arg) { char* mask; - mask = strstr(arg, "/"); - if(mask == NULL) { + mask = strchr(arg, '/'); + if (mask == NULL) { die("Could not parse net/mask\n"); } *mask = '\0'; mask++; - if(inet_aton(arg, &options.netfilternet) == 0) { + if (inet_aton(arg, &options.netfilternet) == 0) die("Invalid network address\n"); - } - if(inet_aton(mask, &options.netfiltermask) == 0) { - die("Invalid network mask\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); + } + } else if (inet_aton(mask, &options.netfiltermask) == 0) + die("Invalid netmask\n"); options.netfilter = 1; @@ -58,7 +68,7 @@ void usage(FILE *fp) { fprintf(fp, "iftop: display bandwidth usage on an interface by host\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" " -h display this message\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" " -n network/netmask show traffic flows in/out of network\n" "\n" -"iftop, version " IFTOP_VERSION "copyright (c) 2002 Paul Warren \n" +"iftop, version " IFTOP_VERSION " copyright (c) 2002 Paul Warren \n" ); }