diff options
author | Daniil Baturin <daniil@baturin.org> | 2013-06-03 04:42:41 -0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2013-06-03 04:42:41 -0700 |
commit | 2dff83837dd516b3110f89f4de15056fbf2d9e58 (patch) | |
tree | 51eacf3eddaa162de007d16f84af4efa452ffc6a /src/ipaddrcheck.c | |
parent | e0d117042121863ef2dab887d691be955842c222 (diff) | |
download | ipaddrcheck-2dff83837dd516b3110f89f4de15056fbf2d9e58.tar.gz ipaddrcheck-2dff83837dd516b3110f89f4de15056fbf2d9e58.zip |
Add check for CIDR format in host vs. net and broadcast checks,
as they can't give meaningul result without prefix length.
Diffstat (limited to 'src/ipaddrcheck.c')
-rw-r--r-- | src/ipaddrcheck.c | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/src/ipaddrcheck.c b/src/ipaddrcheck.c index 1801406..18f5b49 100644 --- a/src/ipaddrcheck.c +++ b/src/ipaddrcheck.c @@ -249,14 +249,40 @@ int main(int argc, char* argv[]) result = is_ipv4_single(address_str); break; case IS_IPV4_HOST: - result = is_ipv4_host(address); + /* Host vs. network address check only makes sense + if prefix length is given */ + if( !is_ipv4_cidr(address_str) ) + { + result = RESULT_FAILURE; + } + else + { + result = is_ipv4_host(address); + } break; case IS_IPV4_NET: - /* XXX: Should we fail this check for single addresses? */ - result = is_ipv4_net(address); + /* Host vs. network address check only makes sense + if prefix length is given */ + if( !is_ipv4_cidr(address_str) ) + { + result = RESULT_FAILURE; + } + else + { + result = is_ipv4_net(address); + } break; case IS_IPV4_BROADCAST: - result = is_ipv4_broadcast(address); + /* Broadcast address check only makes sense + if prefix length is given */ + if( !is_ipv4_cidr(address_str) ) + { + result = RESULT_FAILURE; + } + else + { + result = is_ipv4_broadcast(address); + } break; case IS_IPV4_MULTICAST: result = is_ipv4_multicast(address); @@ -280,10 +306,28 @@ int main(int argc, char* argv[]) result = is_ipv6_single(address_str); break; case IS_IPV6_HOST: - result = is_ipv6_host(address); + /* Host vs. network address check only makes sense + if prefix length is given */ + if( !is_ipv6_cidr(address_str) ) + { + result = RESULT_FAILURE; + } + else + { + result = is_ipv6_host(address); + } break; case IS_IPV6_NET: - result = is_ipv6_net(address); + /* Host vs. network address check only makes sense + if prefix length is given */ + if( !is_ipv6_cidr(address_str) ) + { + result = RESULT_FAILURE; + } + else + { + result = is_ipv6_net(address); + } break; case IS_IPV6_MULTICAST: result = is_ipv6_multicast(address); @@ -304,6 +348,8 @@ int main(int argc, char* argv[]) case NO_ACTION: break; case IS_ANY_HOST: + /* Host vs. network address check only makes sense + if prefix length is given */ if( !is_any_cidr(address_str) ) { result = RESULT_FAILURE; @@ -314,6 +360,8 @@ int main(int argc, char* argv[]) } break; case IS_ANY_NET: + /* Host vs. network address check only makes sense + if prefix length is given */ if( !is_any_cidr(address_str) ) { result = RESULT_FAILURE; |