|
@ -65,6 +65,7 @@ using v8::String; |
|
|
using v8::Value; |
|
|
using v8::Value; |
|
|
|
|
|
|
|
|
typedef class ReqWrap<uv_getaddrinfo_t> GetAddrInfoReqWrap; |
|
|
typedef class ReqWrap<uv_getaddrinfo_t> GetAddrInfoReqWrap; |
|
|
|
|
|
typedef class ReqWrap<uv_getnameinfo_t> GetNameInfoReqWrap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int cmp_ares_tasks(const ares_task_t* a, const ares_task_t* b) { |
|
|
static int cmp_ares_tasks(const ares_task_t* a, const ares_task_t* b) { |
|
@ -958,6 +959,37 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AfterGetNameInfo(uv_getnameinfo_t* req, |
|
|
|
|
|
int status, |
|
|
|
|
|
const char* hostname, |
|
|
|
|
|
const char* service) { |
|
|
|
|
|
GetNameInfoReqWrap* req_wrap = static_cast<GetNameInfoReqWrap*>(req->data); |
|
|
|
|
|
Environment* env = req_wrap->env(); |
|
|
|
|
|
|
|
|
|
|
|
HandleScope handle_scope(env->isolate()); |
|
|
|
|
|
Context::Scope context_scope(env->context()); |
|
|
|
|
|
|
|
|
|
|
|
Local<Value> argv[] = { |
|
|
|
|
|
Integer::New(env->isolate(), status), |
|
|
|
|
|
Null(env->isolate()), |
|
|
|
|
|
Null(env->isolate()) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (status == 0) { |
|
|
|
|
|
// Success
|
|
|
|
|
|
Local<String> js_hostname = OneByteString(env->isolate(), hostname); |
|
|
|
|
|
Local<String> js_service = OneByteString(env->isolate(), service); |
|
|
|
|
|
argv[1] = js_hostname; |
|
|
|
|
|
argv[2] = js_service; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Make the callback into JavaScript
|
|
|
|
|
|
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); |
|
|
|
|
|
|
|
|
|
|
|
delete req_wrap; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void IsIP(const FunctionCallbackInfo<Value>& args) { |
|
|
static void IsIP(const FunctionCallbackInfo<Value>& args) { |
|
|
Environment* env = Environment::GetCurrent(args.GetIsolate()); |
|
|
Environment* env = Environment::GetCurrent(args.GetIsolate()); |
|
|
HandleScope scope(env->isolate()); |
|
|
HandleScope scope(env->isolate()); |
|
@ -1025,6 +1057,39 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void GetNameInfo(const FunctionCallbackInfo<Value>& args) { |
|
|
|
|
|
Environment* env = Environment::GetCurrent(args.GetIsolate()); |
|
|
|
|
|
HandleScope handle_scope(env->isolate()); |
|
|
|
|
|
|
|
|
|
|
|
CHECK(args[0]->IsObject()); |
|
|
|
|
|
CHECK(args[1]->IsString()); |
|
|
|
|
|
CHECK(args[2]->IsUint32()); |
|
|
|
|
|
Local<Object> req_wrap_obj = args[0].As<Object>(); |
|
|
|
|
|
node::Utf8Value ip(args[1]); |
|
|
|
|
|
const unsigned port = args[2]->Uint32Value(); |
|
|
|
|
|
struct sockaddr_storage addr; |
|
|
|
|
|
|
|
|
|
|
|
CHECK(uv_ip4_addr(*ip, port, reinterpret_cast<sockaddr_in*>(&addr)) == 0 || |
|
|
|
|
|
uv_ip6_addr(*ip, port, reinterpret_cast<sockaddr_in6*>(&addr)) == 0); |
|
|
|
|
|
|
|
|
|
|
|
GetNameInfoReqWrap* req_wrap = |
|
|
|
|
|
new GetNameInfoReqWrap(env, |
|
|
|
|
|
req_wrap_obj, |
|
|
|
|
|
AsyncWrap::PROVIDER_GETNAMEINFOREQWRAP); |
|
|
|
|
|
|
|
|
|
|
|
int err = uv_getnameinfo(env->event_loop(), |
|
|
|
|
|
&req_wrap->req_, |
|
|
|
|
|
AfterGetNameInfo, |
|
|
|
|
|
(struct sockaddr*)&addr, |
|
|
|
|
|
NI_NAMEREQD); |
|
|
|
|
|
req_wrap->Dispatched(); |
|
|
|
|
|
if (err) |
|
|
|
|
|
delete req_wrap; |
|
|
|
|
|
|
|
|
|
|
|
args.GetReturnValue().Set(err); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void GetServers(const FunctionCallbackInfo<Value>& args) { |
|
|
static void GetServers(const FunctionCallbackInfo<Value>& args) { |
|
|
HandleScope handle_scope(args.GetIsolate()); |
|
|
HandleScope handle_scope(args.GetIsolate()); |
|
|
Environment* env = Environment::GetCurrent(args.GetIsolate()); |
|
|
Environment* env = Environment::GetCurrent(args.GetIsolate()); |
|
@ -1168,6 +1233,7 @@ static void Initialize(Handle<Object> target, |
|
|
NODE_SET_METHOD(target, "getHostByAddr", Query<GetHostByAddrWrap>); |
|
|
NODE_SET_METHOD(target, "getHostByAddr", Query<GetHostByAddrWrap>); |
|
|
|
|
|
|
|
|
NODE_SET_METHOD(target, "getaddrinfo", GetAddrInfo); |
|
|
NODE_SET_METHOD(target, "getaddrinfo", GetAddrInfo); |
|
|
|
|
|
NODE_SET_METHOD(target, "getnameinfo", GetNameInfo); |
|
|
NODE_SET_METHOD(target, "isIP", IsIP); |
|
|
NODE_SET_METHOD(target, "isIP", IsIP); |
|
|
|
|
|
|
|
|
NODE_SET_METHOD(target, "strerror", StrError); |
|
|
NODE_SET_METHOD(target, "strerror", StrError); |
|
|