From 037d21f508ef664d9592182d7b9b8d6989c28098 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 26 Jun 2024 08:28:35 +0200 Subject: Adding upstream version 1.9.5. Signed-off-by: Daniel Baumann --- iputils.cc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'iputils.cc') diff --git a/iputils.cc b/iputils.cc index 4409997..bd1204e 100644 --- a/iputils.cc +++ b/iputils.cc @@ -366,17 +366,18 @@ void ComboAddress::truncate(unsigned int bits) noexcept *place &= (~((1<(const_cast(dest)); msgh.msg_namelen = dest->getSocklen(); } @@ -387,11 +388,12 @@ size_t sendMsgWithOptions(int fd, const char* buffer, size_t len, const ComboAdd msgh.msg_flags = 0; - if (localItf != 0 && local) { - addCMsgSrcAddr(&msgh, &cbuf, local, localItf); + if (local != nullptr && local->sin4.sin_family != 0) { + addCMsgSrcAddr(&msgh, &cbuf, local, static_cast(localItf)); } - iov.iov_base = reinterpret_cast(const_cast(buffer)); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast): it's the API + iov.iov_base = const_cast(buffer); iov.iov_len = len; msgh.msg_iov = &iov; msgh.msg_iovlen = 1; @@ -405,15 +407,15 @@ size_t sendMsgWithOptions(int fd, const char* buffer, size_t len, const ComboAdd do { #ifdef MSG_FASTOPEN - if (flags & MSG_FASTOPEN && firstTry == false) { + if ((flags & MSG_FASTOPEN) != 0 && !firstTry) { flags &= ~MSG_FASTOPEN; } #endif /* MSG_FASTOPEN */ - ssize_t res = sendmsg(fd, &msgh, flags); + ssize_t res = sendmsg(socketDesc, &msgh, flags); if (res > 0) { - size_t written = static_cast(res); + auto written = static_cast(res); sent += written; if (sent == len) { @@ -425,6 +427,7 @@ size_t sendMsgWithOptions(int fd, const char* buffer, size_t len, const ComboAdd firstTry = false; #endif iov.iov_len -= written; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic): it's the API iov.iov_base = reinterpret_cast(reinterpret_cast(iov.iov_base) + written); } else if (res == 0) { @@ -435,14 +438,12 @@ size_t sendMsgWithOptions(int fd, const char* buffer, size_t len, const ComboAdd if (err == EINTR) { continue; } - else if (err == EAGAIN || err == EWOULDBLOCK || err == EINPROGRESS || err == ENOTCONN) { + if (err == EAGAIN || err == EWOULDBLOCK || err == EINPROGRESS || err == ENOTCONN) { /* EINPROGRESS might happen with non blocking socket, especially with TCP Fast Open */ return sent; } - else { - unixDie("failed in sendMsgWithTimeout"); - } + unixDie("failed in sendMsgWithOptions"); } } while (true); -- cgit v1.2.3