From 5e822c1f3cf6e2bc2481807a3226b56e046707b6 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 13 Feb 2025 12:54:12 -0800 Subject: [PATCH] [posix] set `IPV6_ADDR_PREFERENCES` on trel socket (#10953) --- src/posix/platform/trel.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/posix/platform/trel.cpp b/src/posix/platform/trel.cpp index 758a30288..6e6f566dc 100644 --- a/src/posix/platform/trel.cpp +++ b/src/posix/platform/trel.cpp @@ -181,6 +181,11 @@ static void PrepareSocket(uint16_t &aUdpPort) val = val | O_NONBLOCK; VerifyOrDie(fcntl(sSocket, F_SETFL, val) == 0, OT_EXIT_ERROR_ERRNO); +#if defined(IPV6_ADDR_PREFERENCES) && defined(IPV6_PREFER_SRC_PUBLIC) + val = IPV6_PREFER_SRC_PUBLIC; + setsockopt(sSocket, IPPROTO_IPV6, IPV6_ADDR_PREFERENCES, &val, sizeof(val)); +#endif + // Bind the socket. memset(&sockAddr, 0, sizeof(sockAddr));