From 33523026f266d6df56b8a14b16ccc34902156e4c Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 14 Sep 2023 11:05:14 -0400 Subject: [PATCH] Fix -Wundef issues in src/inet. (#29221) * __MBED__ should be tested for via ifdef. * HAVE_SO_BINDTODEVICE should be an actual config macro. --- src/inet/InetConfig.h | 11 +++++++++++ src/inet/InetInterface.cpp | 4 ++-- src/inet/TCPEndPointImplSockets.cpp | 10 +++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/inet/InetConfig.h b/src/inet/InetConfig.h index 0631a7e14f77da..c3653a4216110f 100644 --- a/src/inet/InetConfig.h +++ b/src/inet/InetConfig.h @@ -272,4 +272,15 @@ #endif #endif // INET_CONFIG_UDP_SOCKET_PKTINFO +/** + * @def HAVE_SO_BINDTODEVICE + * + * @brief + * Should be set to 1 if the SO_BINDTODEVICE option to setsockopt is + * available. + */ +#ifndef HAVE_SO_BINDTODEVICE +#define HAVE_SO_BINDTODEVICE 0 +#endif + // clang-format on diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index 3bc54093ff7d94..571c028fafa8d2 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -586,7 +586,7 @@ short InterfaceIterator::GetFlags() mIntfFlags = intfData.ifr_flags; mIntfFlagsCached = true; } -#if __MBED__ +#ifdef __MBED__ CloseIOCTLSocket(); #endif } @@ -670,7 +670,7 @@ uint8_t InterfaceAddressIterator::GetPrefixLength() { if (mCurAddr->ifa_addr->sa_family == AF_INET6) { -#if !__MBED__ +#ifndef __MBED__ struct sockaddr_in6 & netmask = *reinterpret_cast(mCurAddr->ifa_netmask); return NetmaskToPrefixLength(netmask.sin6_addr.s6_addr, 16); #else // __MBED__ diff --git a/src/inet/TCPEndPointImplSockets.cpp b/src/inet/TCPEndPointImplSockets.cpp index 384337e3342ab4..fc8c6e2da2a77e 100644 --- a/src/inet/TCPEndPointImplSockets.cpp +++ b/src/inet/TCPEndPointImplSockets.cpp @@ -797,7 +797,7 @@ void TCPEndPointImplSockets::HandlePendingIO(System::SocketEvents events) // The socket being writable indicates the connection has completed (successfully or otherwise). if (events.Has(System::SocketEventFlags::kWrite)) { -#if !__MBED__ +#ifndef __MBED__ // Get the connection result from the socket. int osConRes; socklen_t optLen = sizeof(osConRes); @@ -805,11 +805,11 @@ void TCPEndPointImplSockets::HandlePendingIO(System::SocketEvents events) { osConRes = errno; } -#else - // On Mbed OS, connect blocks and never returns EINPROGRESS - // The socket option SO_ERROR is not available. +#else // __MBED__ + // On Mbed OS, connect blocks and never returns EINPROGRESS + // The socket option SO_ERROR is not available. int osConRes = 0; -#endif +#endif // !__MBED__ CHIP_ERROR conRes = CHIP_ERROR_POSIX(osConRes); // Process the connection result.