Ignore network and broadcast for cidrs /31 and /32

fping has previously been strict about network address and broadcast
addreses. In the commit this is loosened a bit to permit fping to ping
cidrs with prefix length 31, which are commonly used for link ranges
(for newer equipment) and length 32 which denotes a single ip address.

For prefix lengths 31 and 32 fping will simply ignore network address
and broadcast addresses, and consider all addresses in range as a
target.
pull/102/head
Martin Topholm 8 years ago
parent 3dd524f127
commit 1264b10784

@ -881,8 +881,8 @@ void add_cidr(char *addr)
net_addr = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);
/* check mask */
if(mask < 1 || mask > 30) {
fprintf(stderr, "Error: netmask must be between 1 and 30 (is: %s)\n", mask_str);
if(mask < 1 || mask > 32) {
fprintf(stderr, "Error: netmask must be between 1 and 32 (is: %s)\n", mask_str);
exit(1);
}
@ -893,8 +893,14 @@ void add_cidr(char *addr)
net_addr &= bitmask;
net_last = net_addr + ((unsigned long) 0x1 << (32-mask)) - 1;
/* add all hosts in that network (excluding network and broadcast address) */
while(++net_addr < net_last) {
/* exclude network and broadcast address for regular prefixes */
if (mask < 31) {
net_last--;
net_addr++;
}
/* add all hosts in that network (net_addr and net_last inclusive) */
for(; net_addr <= net_last; net_addr++) {
struct in_addr in_addr_tmp;
char buffer[20];
in_addr_tmp.s_addr = htonl(net_addr);
@ -902,6 +908,7 @@ void add_cidr(char *addr)
add_name(buffer);
}
freeaddrinfo(addr_res);
}

Loading…
Cancel
Save