diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index eb7d1079f67..db2fb75438e 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -2251,13 +2251,13 @@ void SetServers(const FunctionCallbackInfo& args) { if (!elm->Get(env->context(), 1).ToLocal(&ipValue)) return; if (!elm->Get(env->context(), 2).ToLocal(&portValue)) return; - CHECK(familyValue->Int32Value(env->context()).FromJust()); + CHECK(familyValue->IsInt32()); CHECK(ipValue->IsString()); - CHECK(portValue->Int32Value(env->context()).FromJust()); + CHECK(portValue->IsInt32()); - int fam = familyValue->Int32Value(env->context()).FromJust(); + int32_t fam = familyValue.As()->Value(); node::Utf8Value ip(env->isolate(), ipValue); - int port = portValue->Int32Value(env->context()).FromJust(); + int32_t port = portValue.As()->Value(); if (!csv.empty()) csv += ','; diff --git a/test/parallel/test-dns.js b/test/parallel/test-dns.js index e885a700752..2ac763ffa2d 100644 --- a/test/parallel/test-dns.js +++ b/test/parallel/test-dns.js @@ -134,6 +134,10 @@ const portsExpected = [ dns.setServers(ports); assert.deepStrictEqual(dns.getServers(), portsExpected); +// Port 0 means "use the default port" for c-ares. +dns.setServers(['4.4.4.4:0', '[2001:4860:4860::8888]:0']); +assert.deepStrictEqual(dns.getServers(), ['4.4.4.4', '2001:4860:4860::8888']); + // Link-local IPv6 addresses require a zone index (scope id) to be usable; // c-ares drops link-local servers configured without one. dns.setServers(['[fe80::483a:5aff:fee6:1f04]%eth0']);