Terminate address filter with OS_AF_NULL instead of 0 (AF_UNSPEC)

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2018-10-24 22:32:27 +02:00
parent 40b7b5f423
commit 8fc9535316
7 changed files with 13 additions and 10 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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.
*/

View file

@ -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;

View file

@ -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]);
}

View file

@ -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);
}

View file

@ -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);