[posix] DNS resolver to handle link-local server address (#11548)

When `sendto` is used with a Link-Local IPv6 destination, the index of
the outgoing network interface must be included.
This commit is contained in:
Yang Song
2025-06-02 11:09:27 -07:00
committed by GitHub
parent a7a45b0913
commit c020f86230
+7 -2
View File
@@ -231,8 +231,8 @@ otError Resolver::SendQueryToServer(Transaction *aTxn,
{
otError error = OT_ERROR_NONE;
otIp4Address ip4Addr;
sockaddr_in serverAddr4;
sockaddr_in6 serverAddr6;
sockaddr_in serverAddr4 = {};
sockaddr_in6 serverAddr6 = {};
if (otIp4FromIp4MappedIp6Address(&aServerAddress, &ip4Addr) == OT_ERROR_NONE)
{
@@ -249,6 +249,11 @@ otError Resolver::SendQueryToServer(Transaction *aTxn,
memcpy(&serverAddr6.sin6_addr, &aServerAddress, sizeof(otIp6Address));
serverAddr6.sin6_family = AF_INET6;
serverAddr6.sin6_port = htons(53);
if (IsIp6AddressLinkLocal(aServerAddress))
{
// Network interface index is required for link local destinations
serverAddr6.sin6_scope_id = otSysGetInfraNetifIndex();
}
VerifyOrExit(sendto(aTxn->mUdpFd6, aPacket, aLength, MSG_DONTWAIT, reinterpret_cast<sockaddr *>(&serverAddr6),
sizeof(serverAddr6)) > 0,