summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2026-03-11 10:21:58 -0500
committerGitHub <noreply@github.com>2026-03-11 10:21:58 -0500
commitb00cba165a62d5f0251bc877234ef87c6e741b4e (patch)
tree28512a6afe1767769b9795e964bf709f8a9a1c7b
parent96b9fdcc276a058dea9dedc602a596d27a1fb982 (diff)
parent563fc7def9903c804aca526d0f5f471d76f36fd9 (diff)
downloadipaddrcheck-b00cba165a62d5f0251bc877234ef87c6e741b4e.tar.gz
ipaddrcheck-b00cba165a62d5f0251bc877234ef87c6e741b4e.zip
Merge pull request #21 from dmbaturin/T8374-fix-range-check
T8374: convert addresses to the host byte order before comparison in IPv4 range checks
-rw-r--r--src/ipaddrcheck_functions.c2
-rw-r--r--tests/check_ipaddrcheck.c1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c
index 75d8eec..09830a1 100644
--- a/src/ipaddrcheck_functions.c
+++ b/src/ipaddrcheck_functions.c
@@ -562,7 +562,7 @@ int is_ipv4_range(char* range_str, int prefix_length, int verbose)
struct in_addr* left_in_addr = cidr_to_inaddr(left_addr, NULL);
struct in_addr* right_in_addr = cidr_to_inaddr(right_addr, NULL);
- if( left_in_addr->s_addr <= right_in_addr->s_addr )
+ if( ntohl(left_in_addr->s_addr) <= ntohl(right_in_addr->s_addr) )
{
/* If non-zero prefix_length is given,
check if the right address is within the network of the first one. */
diff --git a/tests/check_ipaddrcheck.c b/tests/check_ipaddrcheck.c
index c4be8b1..fe3876c 100644
--- a/tests/check_ipaddrcheck.c
+++ b/tests/check_ipaddrcheck.c
@@ -408,6 +408,7 @@ START_TEST (test_is_ipv4_range)
ck_assert_int_eq(is_ipv4_range("192.0.2.0-192.0.2.10", 0, 1), RESULT_SUCCESS);
ck_assert_int_eq(is_ipv4_range("192.0.2.-", 0, 1), RESULT_FAILURE);
ck_assert_int_eq(is_ipv4_range("192.0.2.99-192.0.2.11", 0, 1), RESULT_FAILURE);
+ ck_assert_int_eq(is_ipv4_range("192.0.2.0-1.8.2.1", 0, 1), RESULT_FAILURE);
}
END_TEST