]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/iputils.cc
dnsdist: Fix clang-tidy warnings
[thirdparty/pdns.git] / pdns / iputils.cc
index 955b9392c642a116552e38f1a451634c163d32d0..bd1204e3ac86fb40cb973adfafb559a4ad1e5be0 100644 (file)
@@ -366,7 +366,7 @@ void ComboAddress::truncate(unsigned int bits) noexcept
   *place &= (~((1<<bitsleft)-1));
 }
 
-size_t sendMsgWithOptions(int fd, const void* buffer, size_t len, const ComboAddress* dest, const ComboAddress* local, unsigned int localItf, int flags)
+size_t sendMsgWithOptions(int socketDesc, const void* buffer, size_t len, const ComboAddress* dest, const ComboAddress* local, unsigned int localItf, int flags)
 {
   msghdr msgh{};
   iovec iov{};
@@ -376,7 +376,7 @@ size_t sendMsgWithOptions(int fd, const void* buffer, size_t len, const ComboAdd
   memset(&msgh, 0, sizeof(msgh));
   msgh.msg_control = nullptr;
   msgh.msg_controllen = 0;
-  if (dest) {
+  if (dest != nullptr) {
     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-type-const-cast): it's the API
     msgh.msg_name = reinterpret_cast<void*>(const_cast<ComboAddress*>(dest));
     msgh.msg_namelen = dest->getSocklen();
@@ -388,8 +388,8 @@ size_t sendMsgWithOptions(int fd, const void* buffer, size_t len, const ComboAdd
 
   msgh.msg_flags = 0;
 
-  if (local && local->sin4.sin_family != 0) {
-    addCMsgSrcAddr(&msgh, &cbuf, local, localItf);
+  if (local != nullptr && local->sin4.sin_family != 0) {
+    addCMsgSrcAddr(&msgh, &cbuf, local, static_cast<int>(localItf));
   }
 
   // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast): it's the API
@@ -407,15 +407,15 @@ size_t sendMsgWithOptions(int fd, const void* 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<size_t>(res);
+      auto written = static_cast<size_t>(res);
       sent += written;
 
       if (sent == len) {
@@ -427,7 +427,7 @@ size_t sendMsgWithOptions(int fd, const void* buffer, size_t len, const ComboAdd
       firstTry = false;
  #endif
       iov.iov_len -= written;
-      // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
+      // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic): it's the API
       iov.iov_base = reinterpret_cast<void*>(reinterpret_cast<char*>(iov.iov_base) + written);
     }
     else if (res == 0) {
@@ -438,14 +438,12 @@ size_t sendMsgWithOptions(int fd, const void* 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 sendMsgWithOptions");
-      }
+      unixDie("failed in sendMsgWithOptions");
     }
   }
   while (true);