From b30ae18a0bc33ca1b6bf8188b30b0f2bfe4e6b2f Mon Sep 17 00:00:00 2001 From: Max Lv Date: Wed, 14 Oct 2026 21:51:26 +0800 Subject: [PATCH] Build the UDP relay with Clang on musl musl's CMSG_NXTHDR compares a size_t with a ptrdiff_t, which Clang's -Wsign-compare rejects in C++. Call it from one helper that suppresses the warning there. --- src/relay/udp.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/relay/udp.cpp b/src/relay/udp.cpp index e072bbee..bf5f6010 100644 --- a/src/relay/udp.cpp +++ b/src/relay/udp.cpp @@ -45,6 +45,17 @@ using event::Flow; namespace { +#ifdef __linux__ +// musl's CMSG_NXTHDR compares a size_t with a ptrdiff_t. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-compare" +cmsghdr *next_cmsg(msghdr *msg, cmsghdr *c) noexcept +{ + return CMSG_NXTHDR(msg, c); +} +#pragma GCC diagnostic pop +#endif + constexpr int kQosTos = 46 << 2; // DSCP EF, as udprelay.cpp constexpr int kReceiveBurst = 64; constexpr std::uint64_t kTtl2022 = 600; // seconds an idle AEAD-2022 client session is kept @@ -339,7 +350,7 @@ void UdpRelay::receive(Listener &listener) noexcept msg.msg_iovlen = 1; r = recvmsg(listener.poll.fd(), &msg, 0); if (r >= 0) { - for (cmsghdr *c = CMSG_FIRSTHDR(&msg); c != nullptr; c = CMSG_NXTHDR(&msg, c)) { + for (cmsghdr *c = CMSG_FIRSTHDR(&msg); c != nullptr; c = next_cmsg(&msg, c)) { if (c->cmsg_level == SOL_IP && c->cmsg_type == IP_RECVORIGDSTADDR) { std::memcpy(&original, CMSG_DATA(c), sizeof(sockaddr_in)); original.ss_family = AF_INET;