Skip to content

Commit c020f86

Browse files
[posix] DNS resolver to handle link-local server address (openthread#11548)
When `sendto` is used with a Link-Local IPv6 destination, the index of the outgoing network interface must be included.
1 parent a7a45b0 commit c020f86

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/posix/platform/resolver.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ otError Resolver::SendQueryToServer(Transaction *aTxn,
231231
{
232232
otError error = OT_ERROR_NONE;
233233
otIp4Address ip4Addr;
234-
sockaddr_in serverAddr4;
235-
sockaddr_in6 serverAddr6;
234+
sockaddr_in serverAddr4 = {};
235+
sockaddr_in6 serverAddr6 = {};
236236

237237
if (otIp4FromIp4MappedIp6Address(&aServerAddress, &ip4Addr) == OT_ERROR_NONE)
238238
{
@@ -249,6 +249,11 @@ otError Resolver::SendQueryToServer(Transaction *aTxn,
249249
memcpy(&serverAddr6.sin6_addr, &aServerAddress, sizeof(otIp6Address));
250250
serverAddr6.sin6_family = AF_INET6;
251251
serverAddr6.sin6_port = htons(53);
252+
if (IsIp6AddressLinkLocal(aServerAddress))
253+
{
254+
// Network interface index is required for link local destinations
255+
serverAddr6.sin6_scope_id = otSysGetInfraNetifIndex();
256+
}
252257

253258
VerifyOrExit(sendto(aTxn->mUdpFd6, aPacket, aLength, MSG_DONTWAIT, reinterpret_cast<sockaddr *>(&serverAddr6),
254259
sizeof(serverAddr6)) > 0,

0 commit comments

Comments
 (0)