From 8fc95353169b7c1c7755a91a1bfe7740a7d7ec28 Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Wed, 24 Oct 2018 22:32:27 +0200 Subject: [PATCH] Terminate address filter with OS_AF_NULL instead of 0 (AF_UNSPEC) Signed-off-by: Jeroen Koekkoek --- src/core/ddsi/src/ddsi_eth.c | 2 +- src/core/ddsi/src/ddsi_raweth.c | 2 +- src/os/include/os/os_socket.h | 4 +++- src/os/src/os_socket.c | 3 ++- src/os/src/posix/os_platform_ifaddrs.c | 2 +- src/os/src/windows/os_platform_ifaddrs.c | 2 +- src/os/tests/ifaddrs.c | 8 ++++---- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/core/ddsi/src/ddsi_eth.c b/src/core/ddsi/src/ddsi_eth.c index af3eff1..45cb563 100644 --- a/src/core/ddsi/src/ddsi_eth.c +++ b/src/core/ddsi/src/ddsi_eth.c @@ -13,7 +13,7 @@ int ddsi_eth_enumerate_interfaces(ddsi_tran_factory_t fact, os_ifaddrs_t **ifs) { - int afs[] = { AF_INET, 0 }; + int afs[] = { AF_INET, OS_AF_NULL }; (void)fact; diff --git a/src/core/ddsi/src/ddsi_raweth.c b/src/core/ddsi/src/ddsi_raweth.c index 87e9352..807664c 100644 --- a/src/core/ddsi/src/ddsi_raweth.c +++ b/src/core/ddsi/src/ddsi_raweth.c @@ -349,7 +349,7 @@ static void ddsi_raweth_deinit(void) static int ddsi_raweth_enumerate_interfaces (ddsi_tran_factory_t factory, os_ifaddrs_t **interfs) { - int afs[] = { AF_PACKET, 0 }; + int afs[] = { AF_PACKET, OS_AF_NULL }; (void)factory; diff --git a/src/os/include/os/os_socket.h b/src/os/include/os/os_socket.h index bc344a3..511c1b4 100644 --- a/src/os/include/os/os_socket.h +++ b/src/os/include/os/os_socket.h @@ -110,6 +110,8 @@ extern "C" { #define SD_FLAG_IS_SET(flags, flag) ((((uint32_t)(flags) & (uint32_t)(flag))) != 0U) +#define OS_AF_NULL (-1) + /** Network interface attributes */ typedef struct os_ifaddrs_s { struct os_ifaddrs_s *next; @@ -134,7 +136,7 @@ extern "C" { * @param[in] afs NULL-terminated array of address families (AF_xyz) to * restrict resulting set of network interfaces too. NULL to * return all network interfaces for all supported address - * families. + * families. Terminate the array with OS_AF_NULL. * * @returns Returns zero on success or a valid errno value on error. */ diff --git a/src/os/src/os_socket.c b/src/os/src/os_socket.c index 0a39d73..5cb7b71 100644 --- a/src/os/src/os_socket.c +++ b/src/os/src/os_socket.c @@ -52,7 +52,8 @@ const int afs[] = { #if OS_SOCKET_HAS_IPV6 AF_INET6, #endif /* OS_SOCKET_HAS_IPV6 */ - AF_INET + AF_INET, + OS_AF_NULL /* Terminator */ }; const int *const os_supp_afs = afs; diff --git a/src/os/src/posix/os_platform_ifaddrs.c b/src/os/src/posix/os_platform_ifaddrs.c index d1252b9..2872888 100644 --- a/src/os/src/posix/os_platform_ifaddrs.c +++ b/src/os/src/posix/os_platform_ifaddrs.c @@ -83,7 +83,7 @@ os_getifaddrs( sa = sys_ifa->ifa_addr; if (sa != NULL) { use = 0; - for (int i = 0; !use && afs[i] != 0; i++) { + for (int i = 0; !use && afs[i] != OS_AF_NULL; i++) { use = (sa->sa_family == afs[i]); } diff --git a/src/os/src/windows/os_platform_ifaddrs.c b/src/os/src/windows/os_platform_ifaddrs.c index d4b1c76..fb24835 100644 --- a/src/os/src/windows/os_platform_ifaddrs.c +++ b/src/os/src/windows/os_platform_ifaddrs.c @@ -237,7 +237,7 @@ os_getifaddrs( { sa = (struct sockaddr *)addr->Address.lpSockaddr; use = 0; - for (int i = 0; !use && afs[i] != 0; i++) { + for (int i = 0; !use && afs[i] != OS_AF_NULL; i++) { use = (afs[i] == sa->sa_family); } diff --git a/src/os/tests/ifaddrs.c b/src/os/tests/ifaddrs.c index 59b37a2..2f3266f 100644 --- a/src/os/tests/ifaddrs.c +++ b/src/os/tests/ifaddrs.c @@ -65,7 +65,7 @@ CUnit_Test(os_getifaddrs, ipv4) int err; int seen = 0; os_ifaddrs_t *ifa_root, *ifa; - const int afs[] = { AF_INET, 0 }; + const int afs[] = { AF_INET, OS_AF_NULL }; err = os_getifaddrs(&ifa_root, afs); CU_ASSERT_EQUAL_FATAL(err, 0); @@ -109,7 +109,7 @@ CUnit_Test(os_getifaddrs, empty_filter) { int err; os_ifaddrs_t *ifa_root; - const int afs[] = { 0 }; + const int afs[] = { OS_AF_NULL }; err = os_getifaddrs(&ifa_root, afs); CU_ASSERT_EQUAL_FATAL(err, 0); @@ -125,7 +125,7 @@ CUnit_Test(os_getifaddrs, ipv6) int err; int have_ipv6 = 0; os_ifaddrs_t *ifa_root, *ifa; - const int afs[] = { AF_INET6, 0 }; + const int afs[] = { AF_INET6, OS_AF_NULL }; err = os_getifaddrs(&ifa_root, afs); CU_ASSERT_EQUAL_FATAL(err, 0); @@ -161,7 +161,7 @@ CUnit_Test(os_getifaddrs, ipv4_n_ipv6) int have_ipv4 = 0; int have_ipv6 = 0; os_ifaddrs_t *ifa_root, *ifa; - const int afs[] = { AF_INET, AF_INET6, 0 }; + const int afs[] = { AF_INET, AF_INET6, OS_AF_NULL }; err = os_getifaddrs(&ifa_root, afs); CU_ASSERT_EQUAL_FATAL(err, 0);