@@ -9,8 +9,6 @@ using node::MallocedBuffer;
9
9
void ReportEndpoints (uv_handle_t * h, std::ostringstream& out) {
10
10
struct sockaddr_storage addr_storage;
11
11
struct sockaddr * addr = reinterpret_cast <sockaddr*>(&addr_storage);
12
- char hostbuf[NI_MAXHOST];
13
- char portbuf[NI_MAXSERV];
14
12
uv_any_handle* handle = reinterpret_cast <uv_any_handle*>(h);
15
13
int addr_size = sizeof (addr_storage);
16
14
int rc = -1 ;
@@ -26,33 +24,22 @@ void ReportEndpoints(uv_handle_t* h, std::ostringstream& out) {
26
24
break ;
27
25
}
28
26
if (rc == 0 ) {
29
- // getnameinfo will format host and port and handle IPv4/IPv6.
30
- rc = getnameinfo (addr,
31
- addr_size,
32
- hostbuf,
33
- sizeof (hostbuf),
34
- portbuf,
35
- sizeof (portbuf),
36
- NI_NUMERICSERV);
37
- if (rc == 0 ) {
38
- out << std::string (hostbuf) << " :" << std::string (portbuf);
39
- }
27
+ // uv_getnameinfo will format host and port and handle IPv4/IPv6.
28
+ uv_getnameinfo_t local;
29
+ rc = uv_getnameinfo (h->loop , &local, nullptr , addr, NI_NUMERICSERV);
30
+
31
+ if (rc == 0 )
32
+ out << local.host << " :" << local.service ;
40
33
41
34
if (h->type == UV_TCP) {
42
35
// Get the remote end of the connection.
43
36
rc = uv_tcp_getpeername (&(handle->tcp ), addr, &addr_size);
44
37
if (rc == 0 ) {
45
- rc = getnameinfo (addr,
46
- addr_size,
47
- hostbuf,
48
- sizeof (hostbuf),
49
- portbuf,
50
- sizeof (portbuf),
51
- NI_NUMERICSERV);
52
- if (rc == 0 ) {
53
- out << " connected to " ;
54
- out << std::string (hostbuf) << " :" << std::string (portbuf);
55
- }
38
+ uv_getnameinfo_t remote;
39
+ rc = uv_getnameinfo (h->loop , &remote, nullptr , addr, NI_NUMERICSERV);
40
+
41
+ if (rc == 0 )
42
+ out << " connected to " << remote.host << " :" << remote.service ;
56
43
} else if (rc == UV_ENOTCONN) {
57
44
out << " (not connected)" ;
58
45
}
0 commit comments