Skip to content

Commit 19763e6

Browse files
committed
dns, bugfix: fix ipv6 address error.
1 parent 02992c4 commit 19763e6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

fibjs/include/inetAddr.h

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ union inetAddr {
4242
addr6.sin6_family = PF_INET6;
4343
}
4444

45+
void init(sockaddr* addr)
46+
{
47+
if (addr->sa_family == PF_INET)
48+
memmove(this, addr, sizeof(addr4));
49+
else
50+
memmove(this, addr, sizeof(addr6));
51+
}
52+
4553
void setPort(int32_t port)
4654
{
4755
addr4.sin_port = htons(port);

fibjs/src/net/net.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ result_t dns_base::resolve(exlib::string name, obj_ptr<NArray>& retVal, AsyncEve
3737
obj_ptr<NArray> arr = new NArray();
3838
for (ptr = result; ptr != NULL; ptr = ptr->ai_next) {
3939
inetAddr addr_info;
40-
addr_info.init(addr_info.addr4.sin_family);
41-
42-
memcpy(&addr_info, ptr->ai_addr, addr_info.size());
40+
addr_info.init(ptr->ai_addr);
4341
arr->append(addr_info.str());
4442
}
4543

0 commit comments

Comments
 (0)