| 565 | } |
| 566 | |
| 567 | bool ConnectSocketByName(CService& addr, SOCKET& hSocketRet, const char* pszDest, int portDefault, int nTimeout, bool* outProxyConnectionFailed) |
| 568 | { |
| 569 | string strDest; |
| 570 | int port = portDefault; |
| 571 | |
| 572 | if (outProxyConnectionFailed) |
| 573 | *outProxyConnectionFailed = false; |
| 574 | |
| 575 | SplitHostPort(string(pszDest), port, strDest); |
| 576 | |
| 577 | SOCKET hSocket = INVALID_SOCKET; |
| 578 | |
| 579 | CService proxy; |
| 580 | GetNameProxy(proxy); |
| 581 | |
| 582 | CService addrResolved(CNetAddr(strDest, fNameLookup && !HaveNameProxy()), port); |
| 583 | if (addrResolved.IsValid()) { |
| 584 | addr = addrResolved; |
| 585 | return ConnectSocket(addr, hSocketRet, nTimeout); |
| 586 | } |
| 587 | |
| 588 | addr = CService("0.0.0.0:0"); |
| 589 | |
| 590 | if (!HaveNameProxy()) |
| 591 | return false; |
| 592 | // first connect to name proxy server |
| 593 | if (!ConnectSocketDirectly(proxy, hSocket, nTimeout)) { |
| 594 | if (outProxyConnectionFailed) |
| 595 | *outProxyConnectionFailed = true; |
| 596 | return false; |
| 597 | } |
| 598 | // do socks negotiation |
| 599 | if (!Socks5(strDest, (unsigned short)port, hSocket)) |
| 600 | return false; |
| 601 | |
| 602 | hSocketRet = hSocket; |
| 603 | return true; |
| 604 | } |
| 605 | |
| 606 | void CNetAddr::Init() |
| 607 | { |
no test coverage detected