diff --git a/examples/platforms/simulation/mdns_socket.c b/examples/platforms/simulation/mdns_socket.c index fc88c3fe3..efc4a4f10 100644 --- a/examples/platforms/simulation/mdns_socket.c +++ b/examples/platforms/simulation/mdns_socket.c @@ -351,7 +351,7 @@ void otPlatMdnsSendUnicast(otInstance *aInstance, otMessage *aMessage, const otP memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; memcpy(&addr.sin_addr.s_addr, &ip4Addr, sizeof(otIp4Address)); - addr.sin_port = htons(MDNS_PORT); + addr.sin_port = htons(aAddress->mPort); bytes = sendto(sMdnsFd4, buffer, length, 0, (struct sockaddr *)&addr, sizeof(addr)); @@ -363,7 +363,7 @@ void otPlatMdnsSendUnicast(otInstance *aInstance, otMessage *aMessage, const otP memset(&addr6, 0, sizeof(addr6)); addr6.sin6_family = AF_INET6; - addr6.sin6_port = htons(MDNS_PORT); + addr6.sin6_port = htons(aAddress->mPort); memcpy(&addr6.sin6_addr, &aAddress->mAddress, sizeof(otIp6Address)); bytes = sendto(sMdnsFd6, buffer, length, 0, (struct sockaddr *)&addr6, sizeof(addr6)); @@ -411,7 +411,7 @@ void platformMdnsSocketProcess(otInstance *aInstance, const fd_set *aReadFdSet) memset(&addrInfo, 0, sizeof(addrInfo)); otIp4ToIp4MappedIp6Address((otIp4Address *)(&sockaddr.sin_addr.s_addr), &addrInfo.mAddress); - addrInfo.mPort = MDNS_PORT; + addrInfo.mPort = ntohs(sockaddr.sin_port); addrInfo.mInfraIfIndex = sInfraIfIndex; otPlatMdnsHandleReceive(aInstance, message, /* aInUnicast */ false, &addrInfo); @@ -437,7 +437,7 @@ void platformMdnsSocketProcess(otInstance *aInstance, const fd_set *aReadFdSet) memset(&addrInfo, 0, sizeof(addrInfo)); memcpy(&addrInfo.mAddress, &sockaddr6.sin6_addr, sizeof(otIp6Address)); - addrInfo.mPort = MDNS_PORT; + addrInfo.mPort = ntohs(sockaddr6.sin6_port); addrInfo.mInfraIfIndex = sInfraIfIndex; otPlatMdnsHandleReceive(aInstance, message, /* aInUnicast */ false, &addrInfo); diff --git a/src/posix/platform/mdns_socket.cpp b/src/posix/platform/mdns_socket.cpp index 1c1088352..293c0db67 100644 --- a/src/posix/platform/mdns_socket.cpp +++ b/src/posix/platform/mdns_socket.cpp @@ -475,6 +475,7 @@ void MdnsSocket::ReceiveMessage(MsgType aMsgType) VerifyOrExit(rval >= 0, LogCrit("recvfrom() for IPv6 socket failed, errno: %s", strerror(errno))); length = static_cast(rval); ReadIp6AddressFrom(&sockaddr6.sin6_addr, addrInfo.mAddress); + addrInfo.mPort = ntohs(sockaddr6.sin6_port); break; case kIp4Msg: @@ -485,6 +486,7 @@ void MdnsSocket::ReceiveMessage(MsgType aMsgType) VerifyOrExit(rval >= 0, LogCrit("recvfrom() for IPv4 socket failed, errno: %s", strerror(errno))); length = static_cast(rval); otIp4ToIp4MappedIp6Address((otIp4Address *)(&sockaddr.sin_addr.s_addr), &addrInfo.mAddress); + addrInfo.mPort = ntohs(sockaddr.sin_port); break; } @@ -494,7 +496,6 @@ void MdnsSocket::ReceiveMessage(MsgType aMsgType) VerifyOrExit(message != nullptr); SuccessOrExit(otMessageAppend(message, buffer, length)); - addrInfo.mPort = kMdnsPort; addrInfo.mInfraIfIndex = mInfraIfIndex; otPlatMdnsHandleReceive(mInstance, message, /* aInUnicast */ false, &addrInfo);