Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b27b336

Browse filesBrowse files
tniessendanielleadams
authored andcommitted
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: #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>
1 parent 143c428 commit b27b336
Copy full SHA for b27b336

File tree

Expand file treeCollapse file tree

1 file changed

+6
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-16
lines changed
Open diff view settings
Collapse file

‎src/cares_wrap.cc‎

Copy file name to clipboardExpand all lines: src/cares_wrap.cc
+6-16Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,28 +1533,18 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,
15331533
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
15341534
}
15351535

1536-
using ParseIPResult =
1537-
decltype(static_cast<ares_addr_port_node*>(nullptr)->addr);
1538-
1539-
int ParseIP(const char* ip, ParseIPResult* result = nullptr) {
1540-
ParseIPResult tmp;
1541-
if (result == nullptr) result = &tmp;
1542-
if (0 == uv_inet_pton(AF_INET, ip, result)) return 4;
1543-
if (0 == uv_inet_pton(AF_INET6, ip, result)) return 6;
1544-
return 0;
1545-
}
1546-
15471536
void CanonicalizeIP(const FunctionCallbackInfo<Value>& args) {
15481537
Isolate* isolate = args.GetIsolate();
15491538
node::Utf8Value ip(isolate, args[0]);
15501539

1551-
ParseIPResult result;
1552-
const int rc = ParseIP(*ip, &result);
1553-
if (rc == 0) return;
1540+
int af;
1541+
unsigned char result[sizeof(ares_addr_port_node::addr)];
1542+
if (uv_inet_pton(af = AF_INET, *ip, result) != 0 &&
1543+
uv_inet_pton(af = AF_INET6, *ip, result) != 0)
1544+
return;
15541545

15551546
char canonical_ip[INET6_ADDRSTRLEN];
1556-
const int af = (rc == 4 ? AF_INET : AF_INET6);
1557-
CHECK_EQ(0, uv_inet_ntop(af, &result, canonical_ip, sizeof(canonical_ip)));
1547+
CHECK_EQ(0, uv_inet_ntop(af, result, canonical_ip, sizeof(canonical_ip)));
15581548
Local<String> val = String::NewFromUtf8(isolate, canonical_ip)
15591549
.ToLocalChecked();
15601550
args.GetReturnValue().Set(val);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.