From 14019cf6c79d69eae9aaa9af145ca47e88eff3bb Mon Sep 17 00:00:00 2001 From: Aliya Pazylbekova Date: Mon, 25 Feb 2019 11:05:57 -0500 Subject: [PATCH] Modify "qrenderdoc --targetcontrol" command Modify "qrenderdoc --targetcontrol" to accept hostname or ipv4 address. --- qrenderdoc/Code/qrenderdoc.cpp | 33 ++++++++++++++++++---------- renderdoc/os/posix/posix_network.cpp | 6 ++++- renderdoc/os/win32/win32_network.cpp | 31 +++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/qrenderdoc/Code/qrenderdoc.cpp b/qrenderdoc/Code/qrenderdoc.cpp index bc28296f6..7f22d9a40 100644 --- a/qrenderdoc/Code/qrenderdoc.cpp +++ b/qrenderdoc/Code/qrenderdoc.cpp @@ -219,34 +219,45 @@ int main(int argc, char *argv[]) if(parser.isSet(targetcontrol)) { - QRegularExpression regexp(lit("^([a-zA-Z0-9_-]+:)?([0-9]+)$")); + QRegularExpression regexp(lit("^([a-zA-Z\\.0-9_-]+)?(:([0-9]+))?$")); QRegularExpressionMatch match = regexp.match(parser.value(targetcontrol)); if(!match.hasMatch()) { - qCritical() << "--targetcontrol option must be followed by host:port"; + qCritical() << "--targetcontrol option must be followed by host:port or host"; return 1; } QString host = match.captured(1); - if(host.length() > 0 && host[host.length() - 1] == QLatin1Char(':')) - host.chop(1); - bool ok = false; - uint32_t ident = match.captured(2).toUInt(&ok); - - if(ok) + uint32_t ident = 0; + if(match.capturedLength(2) > 0) { - remoteHost = host; - remoteIdent = ident; + ident = match.captured(3).toUInt(&ok); } else { - qCritical() << "--targetcontrol parameter" << match.captured(1) << "malformed"; + // no port specified, find the first open port. + ident = RENDERDOC_EnumerateRemoteTargets(host.toLocal8Bit().data(), ident); + ok = (ident != 0); + } + + if(!ok) + { + if(match.capturedLength(2) > 0) + { + qCritical() << "--targetcontrol port " << match.captured(3) << "malformed"; + } + else + { + qCritical() << "All ports are busy, cannot find an available port"; + } return 1; } + remoteHost = host; + remoteIdent = ident; } QString crashReportPath; diff --git a/renderdoc/os/posix/posix_network.cpp b/renderdoc/os/posix/posix_network.cpp index d7e5089c0..7bdf11beb 100644 --- a/renderdoc/os/posix/posix_network.cpp +++ b/renderdoc/os/posix/posix_network.cpp @@ -425,7 +425,11 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS) hints.ai_protocol = IPPROTO_TCP; addrinfo *addrResult = NULL; - getaddrinfo(host, portstr, &hints, &addrResult); + int res = getaddrinfo(host, portstr, &hints, &addrResult); + if(res != 0) + { + RDCDEBUG("%s", gai_strerror(res)); + } for(addrinfo *ptr = addrResult; ptr != NULL; ptr = ptr->ai_next) { diff --git a/renderdoc/os/win32/win32_network.cpp b/renderdoc/os/win32/win32_network.cpp index 5b4dd4139..2067523d7 100644 --- a/renderdoc/os/win32/win32_network.cpp +++ b/renderdoc/os/win32/win32_network.cpp @@ -66,6 +66,30 @@ static std::string wsaerr_string(int err) return "WSAEHOSTDOWN: A socket operation failed because the destination host was down."; case WSAEHOSTUNREACH: return "WSAETIMEDOUT: A socket operation was attempted to an unreachable host."; + case WSATRY_AGAIN: return "WSATRY_AGAIN: A temporary failure in name resolution occurred."; + case WSAEINVAL: + return "WSAEINVAL: An invalid value was provided for the ai_flags member of the pHints " + "parameter."; + case WSANO_RECOVERY: + return "WSANO_RECOVERY: A nonrecoverable failure in name resolution occurred."; + case WSAEAFNOSUPPORT: + return "WSAEAFNOSUPPORT: The ai_family member of the pHints parameter is not supported."; + case WSA_NOT_ENOUGH_MEMORY: + return "WSA_NOT_ENOUGH_MEMORY: A memory allocation failure occurred."; + case WSAHOST_NOT_FOUND: + return "WSAHOST_NOT_FOUND: The name does not resolve for the supplied parameters or the " + "pNodeName and pServiceName parameters were not provided."; + case WSATYPE_NOT_FOUND: + return "WSATYPE_NOT_FOUND: The pServiceName parameter is not supported for the specified " + "ai_socktype member of the pHints parameter."; + case WSAESOCKTNOSUPPORT: + return "WSAESOCKTNOSUPPORT: The ai_socktype member of the pHints parameter is not supported."; + case WSANO_DATA: + return "WSANO_DATA: The requested name is valid, but no data of the requested type was " + "found."; + case WSANOTINITIALISED: + return "WSANOTINITIALISED: A successful WSAStartup call must occur before using this " + "function."; default: break; } @@ -386,7 +410,12 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS) std::wstring whost = StringFormat::UTF82Wide(string(host)); addrinfoW *addrResult = NULL; - GetAddrInfoW(whost.c_str(), portwstr, &hints, &addrResult); + int res = GetAddrInfoW(whost.c_str(), portwstr, &hints, &addrResult); + if(res != 0) + { + RDCDEBUG("%s", wsaerr_string(res).c_str()); + return NULL; + } for(addrinfoW *ptr = addrResult; ptr != NULL; ptr = ptr->ai_next) {