summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/valid_address.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/valid_address.c b/src/valid_address.c
index 2f93c257..1053693e 100644
--- a/src/valid_address.c
+++ b/src/valid_address.c
@@ -62,20 +62,23 @@ static int valid_ipv4(const char *str)
return 0;
}
- if (~addr == 0) {
- fprintf(stderr,
- "Can not assign broadcast address as IP address\n");
- return 0;
- }
-
if (plen < 31) {
uint32_t net_mask = ~0 << (32 - plen);
+ uint32_t broadcast = (addr & net_mask) | (~0 &~ net_mask);
+
if ((addr & net_mask) == addr) {
fprintf(stderr,
"Can not assign network address as IP address\n");
return 0;
}
+
+ if (addr == broadcast) {
+ fprintf(stderr,
+ "Can not assign broadcast address as IP address\n");
+ return 0;
+ }
}
+
return 1;
bad_addr: