diff options
author | Eugene Ostroukhov <eostroukhov@chromium.org> | 2017-03-02 02:52:43 +0300 |
---|---|---|
committer | Eugene Ostroukhov <eostroukhov@chromium.org> | 2017-03-13 20:41:51 +0300 |
commit | b170fb7c55c15a5f29b1f6feef520c65849871dc (patch) | |
tree | 22c0c08a1bae68200345d19a53d51f79492a9459 /src/inspector_socket_server.cc | |
parent | 608ea942726e491de7327a3fe32cb5a715026c07 (diff) |
inspector: proper WS URLs when bound to 0.0.0.0
JSON target list response will now return appropriate IP address
for instances listening on 0.0.0.0.
Refs: https://github.com/nodejs/node/issues/11591
PR-URL: https://github.com/nodejs/node/pull/11755
Reviewed-By: James Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/inspector_socket_server.cc')
-rw-r--r-- | src/inspector_socket_server.cc | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/inspector_socket_server.cc b/src/inspector_socket_server.cc index ee44a69a683..1c8fa70b65a 100644 --- a/src/inspector_socket_server.cc +++ b/src/inspector_socket_server.cc @@ -139,6 +139,28 @@ void SendProtocolJson(InspectorSocket* socket) { SendHttpResponse(socket, data); } +int GetSocketHost(uv_tcp_t* socket, std::string* out_host) { + char ip[INET6_ADDRSTRLEN]; + sockaddr_storage addr; + int len = sizeof(addr); + int err = uv_tcp_getsockname(socket, + reinterpret_cast<struct sockaddr*>(&addr), + &len); + if (err != 0) + return err; + if (addr.ss_family == AF_INET6) { + const sockaddr_in6* v6 = reinterpret_cast<const sockaddr_in6*>(&addr); + err = uv_ip6_name(v6, ip, sizeof(ip)); + } else { + const sockaddr_in* v4 = reinterpret_cast<const sockaddr_in*>(&addr); + err = uv_ip4_name(v4, ip, sizeof(ip)); + } + if (err != 0) + return err; + *out_host = ip; + return err; +} + int GetPort(uv_tcp_t* socket, int* out_port) { sockaddr_storage addr; int len = sizeof(addr); @@ -341,7 +363,9 @@ void InspectorSocketServer::SendListResponse(InspectorSocket* socket) { } } if (!connected) { - std::string address = GetWsUrl(host_, port_, id); + std::string host; + GetSocketHost(&socket->client, &host); + std::string address = GetWsUrl(host, port_, id); std::ostringstream frontend_url; frontend_url << "chrome-devtools://devtools/bundled"; frontend_url << "/inspector.html?experiments=true&v8only=true&ws="; |