diff --git a/frameworks/js/napi/socket/options/src/net_address.cpp b/frameworks/js/napi/socket/options/src/net_address.cpp index ad41f4da..15052026 100644 --- a/frameworks/js/napi/socket/options/src/net_address.cpp +++ b/frameworks/js/napi/socket/options/src/net_address.cpp @@ -17,6 +17,7 @@ #include "net_address.h" #include "netstack_log.h" +#include "socket_exec_common.h" #include "securec.h" namespace OHOS::NetStack::Socket { @@ -32,6 +33,14 @@ void NetAddress::SetIpAddress(const std::string &address) if (address.empty()) { return; } + if (address == "localhost") { + if (family_ == Family::IPv4) { + address_ = ConvertAddressToIp(address, AF_INET); + } else if (family_ == Family::IPv6) { + address_ = ConvertAddressToIp(address, AF_INET6); + } + return; + } if (family_ == Family::IPv4) { in6_addr ipv6{}; if (inet_pton(AF_INET6, address.c_str(), &ipv6) > 0) {