diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2011-01-03 12:51:53 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2011-01-03 12:51:53 -0800 |
commit | d0312e91bad0d9d3741d61791928ac1b663a7f29 (patch) | |
tree | 6c25029a60531c2c42bf2a7d2f11904fec284aa1 | |
parent | acebe7581e10462551ea75327fc4de4770e1a686 (diff) | |
download | vyatta-cfg-system-d0312e91bad0d9d3741d61791928ac1b663a7f29.tar.gz vyatta-cfg-system-d0312e91bad0d9d3741d61791928ac1b663a7f29.zip |
Fix check for broadcast address
Bug 6625
The validate address function was not accounting for prefix length.
-rw-r--r-- | src/valid_address.c | 15 |
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: |