mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 07:37:46 +00:00
[posix] fix build warnings/errors on macOS (#5839)
This commit is contained in:
+17
-12
@@ -79,15 +79,20 @@ static bool IsMulticast(const otIp6Address &aAddress)
|
||||
|
||||
static otError transmitPacket(int aFd, uint8_t *aPayload, uint16_t aLength, const otMessageInfo &aMessageInfo)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
// use fixed value for CMSG_SPACE is not a constant expression on macOS
|
||||
constexpr size_t kBufferSize = 128;
|
||||
#else
|
||||
constexpr size_t kBufferSize = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int));
|
||||
#endif
|
||||
struct sockaddr_in6 peerAddr;
|
||||
uint8_t
|
||||
control[OT_APPLE_IGNORE_GNU_FOLDING_CONSTANT(CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int)))];
|
||||
size_t controlLength = 0;
|
||||
struct iovec iov;
|
||||
struct msghdr msg;
|
||||
struct cmsghdr *cmsg;
|
||||
ssize_t rval;
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t control[kBufferSize];
|
||||
size_t controlLength = 0;
|
||||
struct iovec iov;
|
||||
struct msghdr msg;
|
||||
struct cmsghdr * cmsg;
|
||||
ssize_t rval;
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
memset(&peerAddr, 0, sizeof(peerAddr));
|
||||
peerAddr.sin6_port = htons(aMessageInfo.mPeerPort);
|
||||
@@ -108,7 +113,7 @@ static otError transmitPacket(int aFd, uint8_t *aPayload, uint16_t aLength, cons
|
||||
msg.msg_name = &peerAddr;
|
||||
msg.msg_namelen = sizeof(peerAddr);
|
||||
msg.msg_control = control;
|
||||
msg.msg_controllen = sizeof(control);
|
||||
msg.msg_controllen = static_cast<decltype(msg.msg_controllen)>(sizeof(control));
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_flags = 0;
|
||||
@@ -149,7 +154,7 @@ static otError transmitPacket(int aFd, uint8_t *aPayload, uint16_t aLength, cons
|
||||
#ifdef __APPLE__
|
||||
msg.msg_controllen = static_cast<socklen_t>(controlLength);
|
||||
#else
|
||||
msg.msg_controllen = controlLength;
|
||||
msg.msg_controllen = controlLength;
|
||||
#endif
|
||||
|
||||
rval = sendmsg(aFd, &msg, 0);
|
||||
@@ -299,7 +304,7 @@ otError otPlatUdpBindToNetif(otUdpSocket *aUdpSocket, otNetifIdentifier aNetifId
|
||||
{
|
||||
case OT_NETIF_UNSPECIFIED:
|
||||
{
|
||||
#if __linux__
|
||||
#ifdef __linux__
|
||||
VerifyOrExit(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, nullptr, 0) == 0, error = OT_ERROR_FAILED);
|
||||
#else // __NetBSD__ || __FreeBSD__ || __APPLE__
|
||||
unsigned int netifIndex = 0;
|
||||
@@ -310,7 +315,7 @@ otError otPlatUdpBindToNetif(otUdpSocket *aUdpSocket, otNetifIdentifier aNetifId
|
||||
}
|
||||
case OT_NETIF_THREAD:
|
||||
{
|
||||
#if __linux__
|
||||
#ifdef __linux__
|
||||
VerifyOrExit(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &gNetifName, strlen(gNetifName)) == 0,
|
||||
error = OT_ERROR_FAILED);
|
||||
#else // __NetBSD__ || __FreeBSD__ || __APPLE__
|
||||
|
||||
Reference in New Issue
Block a user