| 495 | } |
| 496 | |
| 497 | bool ConnectSocketByName(CService& addr, SOCKET& hSocketRet, const char* pszDest, int portDefault, int nTimeout) { |
| 498 | string strDest; |
| 499 | int port = portDefault; |
| 500 | SplitHostPort(string(pszDest), port, strDest); |
| 501 | |
| 502 | SOCKET hSocket = INVALID_SOCKET; |
| 503 | |
| 504 | ProxyType nameproxy; |
| 505 | GetNameProxy(nameproxy); |
| 506 | |
| 507 | CService addrResolved(CNetAddr(strDest, fNameLookup && !nameproxy.second), port); |
| 508 | if (addrResolved.IsValid()) { |
| 509 | addr = addrResolved; |
| 510 | return ConnectSocket(addr, hSocketRet, nTimeout); |
| 511 | } |
| 512 | addr = CService("0.0.0.0:0"); |
| 513 | if (!nameproxy.second) |
| 514 | return false; |
| 515 | if (!ConnectSocketDirectly(nameproxy.first, hSocket, nTimeout)) |
| 516 | return false; |
| 517 | |
| 518 | switch (nameproxy.second) { |
| 519 | default: |
| 520 | case 4: |
| 521 | closesocket(hSocket); |
| 522 | return false; |
| 523 | case 5: |
| 524 | if (!Socks5(strDest, port, hSocket)) |
| 525 | return false; |
| 526 | break; |
| 527 | } |
| 528 | |
| 529 | hSocketRet = hSocket; |
| 530 | return true; |
| 531 | } |
| 532 | |
| 533 | bool LookupSubNet(const char* pszName, CSubNet& ret) { |
| 534 | std::string strSubnet(pszName); |
no test coverage detected