diff options
author | pdw <> | 2002-10-10 14:11:12 +0000 |
---|---|---|
committer | pdw <> | 2002-10-10 14:11:12 +0000 |
commit | c1f017231c5a6b5314804ea390512e336a53c2ea (patch) | |
tree | e34dbaf994f62530d19e88a1aa6fdeddc914f385 /options.c | |
parent | acad1ac4b5df2808981e38a9436070693982a1ed (diff) | |
download | iftop-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.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -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; |