mirror of
https://gitee.com/openharmony/communication_netstack
synced 2024-11-27 09:02:33 +00:00
!1553 fix bind localhost
Merge pull request !1553 from maosiping/master
This commit is contained in:
commit
96a456a65f
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user