summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2011-01-03 12:51:53 -0800
committerMohit Mehta <mohit@vyatta.com>2011-01-04 17:47:15 -0800
commitb0696618f824100c0f5b1c5b8ed37cb05c0a77ec (patch)
treecbf470b3e66af752bd0de988b9ae6282481b3112 /src
parent5ad0c4c085e189532121cff3101bcc91353c4834 (diff)
downloadvyatta-cfg-system-b0696618f824100c0f5b1c5b8ed37cb05c0a77ec.tar.gz
vyatta-cfg-system-b0696618f824100c0f5b1c5b8ed37cb05c0a77ec.zip
Fix check for broadcast address
Bug 6625 The validate address function was not accounting for prefix length. (cherry picked from commit d0312e91bad0d9d3741d61791928ac1b663a7f29)
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: