Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2022-09-29 17:14:13 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2022-10-05 13:54:16 +0300
commitb27b336a7a2a62a2612bfc97a7333f6f94b63d66 (patch)
treed74605268ec1f320e9190b89c9473840d77e24b1 /src
parent143c428cae123db9244453f210a7abac181ec8aa (diff)
src: remove ParseIP() in cares_wrap.cc
This function is only used in one place where the result argument is never nullptr, so remove special handling of that case. Also, instead of returning magic values 0/4/6 and then later translating those into error/AF_INET/AF_INET6, use AF_INET/AF_INET6 directly. Lastly, inline the function, which is simpler overall. PR-URL: https://github.com/nodejs/node/pull/44771 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/cares_wrap.cc22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc
index eb3ebceeca6..959f609fdee 100644
--- a/src/cares_wrap.cc
+++ b/src/cares_wrap.cc
@@ -1533,28 +1533,18 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
}
-using ParseIPResult =
- decltype(static_cast<ares_addr_port_node*>(nullptr)->addr);
-
-int ParseIP(const char* ip, ParseIPResult* result = nullptr) {
- ParseIPResult tmp;
- if (result == nullptr) result = &tmp;
- if (0 == uv_inet_pton(AF_INET, ip, result)) return 4;
- if (0 == uv_inet_pton(AF_INET6, ip, result)) return 6;
- return 0;
-}
-
void CanonicalizeIP(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
node::Utf8Value ip(isolate, args[0]);
- ParseIPResult result;
- const int rc = ParseIP(*ip, &result);
- if (rc == 0) return;
+ int af;
+ unsigned char result[sizeof(ares_addr_port_node::addr)];
+ if (uv_inet_pton(af = AF_INET, *ip, result) != 0 &&
+ uv_inet_pton(af = AF_INET6, *ip, result) != 0)
+ return;
char canonical_ip[INET6_ADDRSTRLEN];
- const int af = (rc == 4 ? AF_INET : AF_INET6);
- CHECK_EQ(0, uv_inet_ntop(af, &result, canonical_ip, sizeof(canonical_ip)));
+ CHECK_EQ(0, uv_inet_ntop(af, result, canonical_ip, sizeof(canonical_ip)));
Local<String> val = String::NewFromUtf8(isolate, canonical_ip)
.ToLocalChecked();
args.GetReturnValue().Set(val);