diff options
author | cjihrig <cjihrig@gmail.com> | 2019-02-06 10:41:09 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-02-08 11:32:08 -0500 |
commit | 679c23f2ae1e62443f8d90e653824007ce174139 (patch) | |
tree | 84b98c7fd3a96573adb2a297fc87140a31b6479b | |
parent | 582c12260ed99ebe7710894c2dab29435b1bebdc (diff) | |
download | android-node-v8-679c23f2ae1e62443f8d90e653824007ce174139.tar.gz android-node-v8-679c23f2ae1e62443f8d90e653824007ce174139.tar.bz2 android-node-v8-679c23f2ae1e62443f8d90e653824007ce174139.zip |
report: use uv_getnameinfo() for socket endpoints
PR-URL: https://github.com/nodejs/node/pull/25962
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
-rw-r--r-- | src/node_report_utils.cc | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/src/node_report_utils.cc b/src/node_report_utils.cc index f827eadede..34fa1b7405 100644 --- a/src/node_report_utils.cc +++ b/src/node_report_utils.cc @@ -9,8 +9,6 @@ using node::MallocedBuffer; void ReportEndpoints(uv_handle_t* h, std::ostringstream& out) { struct sockaddr_storage addr_storage; struct sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); - char hostbuf[NI_MAXHOST]; - char portbuf[NI_MAXSERV]; uv_any_handle* handle = reinterpret_cast<uv_any_handle*>(h); int addr_size = sizeof(addr_storage); int rc = -1; @@ -26,33 +24,22 @@ void ReportEndpoints(uv_handle_t* h, std::ostringstream& out) { break; } if (rc == 0) { - // getnameinfo will format host and port and handle IPv4/IPv6. - rc = getnameinfo(addr, - addr_size, - hostbuf, - sizeof(hostbuf), - portbuf, - sizeof(portbuf), - NI_NUMERICSERV); - if (rc == 0) { - out << std::string(hostbuf) << ":" << std::string(portbuf); - } + // uv_getnameinfo will format host and port and handle IPv4/IPv6. + uv_getnameinfo_t local; + rc = uv_getnameinfo(h->loop, &local, nullptr, addr, NI_NUMERICSERV); + + if (rc == 0) + out << local.host << ":" << local.service; if (h->type == UV_TCP) { // Get the remote end of the connection. rc = uv_tcp_getpeername(&(handle->tcp), addr, &addr_size); if (rc == 0) { - rc = getnameinfo(addr, - addr_size, - hostbuf, - sizeof(hostbuf), - portbuf, - sizeof(portbuf), - NI_NUMERICSERV); - if (rc == 0) { - out << " connected to "; - out << std::string(hostbuf) << ":" << std::string(portbuf); - } + uv_getnameinfo_t remote; + rc = uv_getnameinfo(h->loop, &remote, nullptr, addr, NI_NUMERICSERV); + + if (rc == 0) + out << " connected to " << remote.host << ":" << remote.service; } else if (rc == UV_ENOTCONN) { out << " (not connected)"; } |