diff options
author | Daniil Baturin <daniil@baturin.org> | 2013-06-01 13:34:05 -0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2013-06-01 13:34:05 -0700 |
commit | e2faec5f111fd733b56f8842cb50998cefccd926 (patch) | |
tree | eda7e09a268b00a11d189ab3812afdd88ccb9aa0 | |
parent | 00f98b395795533a9a424fa9bd55e52957ad1031 (diff) | |
download | ipaddrcheck-e2faec5f111fd733b56f8842cb50998cefccd926.tar.gz ipaddrcheck-e2faec5f111fd733b56f8842cb50998cefccd926.zip |
Fix is_ipv4_broadcast() behaviour, don't return success for addresses
that can't be broadcast by definition (IPv6, IPv4 p-t-p).
-rw-r--r-- | src/ipaddrcheck_functions.c | 6 | ||||
-rw-r--r-- | tests/check_ipaddrcheck.c | 10 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c index 061ba8f..2ba8de2 100644 --- a/src/ipaddrcheck_functions.c +++ b/src/ipaddrcheck_functions.c @@ -244,7 +244,11 @@ int is_ipv4_broadcast(CIDR *address) { int result; - if( cidr_equals(address, cidr_addr_broadcast(address)) == 0 ) + /* The very concept of broadcast address doesn't apply to + IPv6 and point-to-point or /32 IPv4 */ + if( (cidr_get_proto(address) == CIDR_IPV4) && + (cidr_equals(address, cidr_addr_broadcast(address)) == 0 ) && + (cidr_get_pflen(address) < 31) ) { result = RESULT_SUCCESS; } diff --git a/tests/check_ipaddrcheck.c b/tests/check_ipaddrcheck.c index 542093e..cdc138d 100644 --- a/tests/check_ipaddrcheck.c +++ b/tests/check_ipaddrcheck.c @@ -161,6 +161,16 @@ START_TEST (test_is_ipv4_broadcast) CIDR* bad_address = cidr_from_str(bad_address_str); ck_assert_int_eq(is_ipv4_broadcast(bad_address), RESULT_FAILURE); cidr_free(bad_address); + + char* bad_address_str_ptp = "192.0.2.1/31"; + CIDR* bad_address_ptp = cidr_from_str(bad_address_str_ptp); + ck_assert_int_eq(is_ipv4_broadcast(bad_address_ptp), RESULT_FAILURE); + cidr_free(bad_address_ptp); + + char* bad_address_str_v6 = "2001:0db8:ffff:ffff:ffff:ffff:ffff:ffff/32"; + CIDR* bad_address_v6 = cidr_from_str(bad_address_str_v6); + ck_assert_int_eq(is_ipv4_broadcast(bad_address_v6), RESULT_FAILURE); + cidr_free(bad_address_v6); } END_TEST |