summaryrefslogtreecommitdiff
path: root/options.c
diff options
context:
space:
mode:
authorpdw <>2002-10-10 14:11:12 +0000
committerpdw <>2002-10-10 14:11:12 +0000
commitc1f017231c5a6b5314804ea390512e336a53c2ea (patch)
treee34dbaf994f62530d19e88a1aa6fdeddc914f385 /options.c
parentacad1ac4b5df2808981e38a9436070693982a1ed (diff)
downloadiftop-c1f017231c5a6b5314804ea390512e336a53c2ea.zip
Added service hash for resolving port/protocol numbers to names.
Minor fix to handling of netmasks end /32.
Diffstat (limited to 'options.c')
-rw-r--r--options.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/options.c b/options.c
index 5f1fcd3..7802a56 100644
--- a/options.c
+++ b/options.c
@@ -87,18 +87,31 @@ static void set_net_filter(char* arg) {
if (inet_aton(arg, &options.netfilternet) == 0)
die("Invalid network address\n");
/* Accept a netmask like /24 or /255.255.255.0. */
- if (!mask[strspn(mask, "0123456789")]) {
+ if (mask[strspn(mask, "0123456789")] == '\0') {
+ /* Whole string is numeric */
int n;
n = atoi(mask);
- if (n > 32)
+ if (n > 32) {
die("Invalid netmask");
+ }
else {
- uint32_t mm = 0xffffffffl;
- mm >>= n;
- options.netfiltermask.s_addr = htonl(~mm);
+ if(n == 32) {
+ /* This needs to be special cased, although I don't fully
+ * understand why -pdw
+ */
+ options.netfiltermask.s_addr = htonl(0xffffffffl);
+ }
+ else {
+ uint32_t mm = 0xffffffffl;
+ mm >>= n;
+ options.netfiltermask.s_addr = htonl(~mm);
+ }
}
- } else if (inet_aton(mask, &options.netfiltermask) == 0)
+ }
+ else if (inet_aton(mask, &options.netfiltermask) == 0) {
die("Invalid netmask\n");
+ }
+ options.netfilternet.s_addr = options.netfilternet.s_addr & options.netfiltermask.s_addr;
options.netfilter = 1;