diff --git a/src/hx/libs/std/Socket.cpp b/src/hx/libs/std/Socket.cpp index 1417e7b5e..3b244d215 100644 --- a/src/hx/libs/std/Socket.cpp +++ b/src/hx/libs/std/Socket.cpp @@ -353,32 +353,26 @@ Array _hx_std_socket_read( Dynamic o ) **/ int _hx_std_host_resolve( String host ) { - unsigned int ip; + hx::EnterGCFreeZone(); - hx::EnterGCFreeZone(); - hx::strbuf buf; - ip = inet_addr(host.utf8_str(&buf)); - if( ip == INADDR_NONE ) - { - struct hostent *h = 0; - hx::strbuf hostBuf; - -# if defined(NEKO_WINDOWS) || defined(NEKO_MAC) || defined(BLACKBERRY) || defined(EMSCRIPTEN) - h = gethostbyname(host.utf8_str(&hostBuf)); -# else - struct hostent hbase; - char buf[1024]; - int errcode; - gethostbyname_r(host.utf8_str(&hostBuf),&hbase,buf,1024,&h,&errcode); -# endif - if( !h ) { - hx::ExitGCFreeZone(); - return hx::Throw( HX_CSTRING("Unknown host:") + host ); - } - ip = *((unsigned int*)h->h_addr); - } - hx::ExitGCFreeZone(); - return ip; + auto result = (addrinfo*)nullptr; + auto hints = addrinfo(); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + + if (0 != getaddrinfo(host.utf8_str(), nullptr, &hints, &result)) + { + hx::ExitGCFreeZone(); + + return hx::Throw(HX_CSTRING("Unknown host:") + host); + } + + auto ipv4 = reinterpret_cast(result->ai_addr); + auto ip = ipv4->sin_addr.S_un; + + hx::ExitGCFreeZone(); + + return ip.S_addr; } #ifdef DYNAMIC_INET_FUNCS