12 #ifdef HAVE_GETADDRINFO_A
25 #include <arpa/inet.h>
30 #include <boost/algorithm/string/case_conv.hpp>
31 #include <boost/algorithm/string/predicate.hpp>
33 #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
34 #define MSG_NOSIGNAL 0
50 static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
56 if (net ==
"tor" || net ==
"onion")
return NET_TOR;
58 if (net ==
"i2p")
return NET_NATIVE_I2P;
70 case NET_NATIVE_I2P:
return "i2p";
77 void SplitHostPort(std::string in,
int &portOut, std::string &hostOut) {
78 size_t colon = in.find_last_of(
':');
80 bool fHaveColon = colon != in.npos;
81 bool fBracketed = fHaveColon && (in[0]==
'[' && in[colon-1]==
']');
82 bool fMultiColon = fHaveColon && (in.find_last_of(
':',colon-1) != in.npos);
83 if (fHaveColon && (colon==0 || fBracketed || !fMultiColon)) {
85 int n = strtol(in.c_str() + colon + 1, &endp, 10);
86 if (endp && *endp == 0 && n >= 0) {
87 in = in.substr(0, colon);
88 if (n > 0 && n < 0x10000)
92 if (in.size()>0 && in[0] ==
'[' && in[in.size()-1] ==
']')
93 hostOut = in.substr(1, in.size()-2);
98 bool static LookupIntern(
const char *pszName, std::vector<CNetAddr>& vIP,
unsigned int nMaxSolutions,
bool fAllowLookup)
104 std::string strName( pszName );
122 #ifdef HAVE_GETADDRINFO_A
123 struct in_addr ipv4_addr;
124 #ifdef HAVE_INET_PTON
125 if (inet_pton(AF_INET, pszName, &ipv4_addr) > 0) {
130 struct in6_addr ipv6_addr;
131 if (inet_pton(AF_INET6, pszName, &ipv6_addr) > 0) {
136 ipv4_addr.s_addr = inet_addr(pszName);
137 if (ipv4_addr.s_addr != INADDR_NONE) {
144 struct addrinfo aiHint;
145 memset(&aiHint, 0,
sizeof(
struct addrinfo));
146 aiHint.ai_socktype = SOCK_STREAM;
147 aiHint.ai_protocol = IPPROTO_TCP;
148 aiHint.ai_family = AF_UNSPEC;
150 aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
152 aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
155 struct addrinfo *aiRes = NULL;
156 #ifdef HAVE_GETADDRINFO_A
157 struct gaicb gcb, *query = &gcb;
158 memset(query, 0,
sizeof(
struct gaicb));
159 gcb.ar_name = pszName;
160 gcb.ar_request = &aiHint;
161 int nErr = getaddrinfo_a(GAI_NOWAIT, &query, 1, NULL);
170 struct timespec ts = { 2, 0 };
171 gai_suspend(&query, 1, &ts);
172 boost::this_thread::interruption_point();
174 nErr = gai_error(query);
176 aiRes = query->ar_result;
177 }
while (nErr == EAI_INPROGRESS);
179 int nErr = getaddrinfo(pszName, NULL, &aiHint, &aiRes);
184 struct addrinfo *aiTrav = aiRes;
185 while (aiTrav != NULL && (nMaxSolutions == 0 || vIP.size() < nMaxSolutions))
187 if (aiTrav->ai_family == AF_INET)
189 assert(aiTrav->ai_addrlen >=
sizeof(sockaddr_in));
190 vIP.push_back(
CNetAddr(((
struct sockaddr_in*)(aiTrav->ai_addr))->sin_addr));
193 if (aiTrav->ai_family == AF_INET6)
195 assert(aiTrav->ai_addrlen >=
sizeof(sockaddr_in6));
196 vIP.push_back(
CNetAddr(((
struct sockaddr_in6*)(aiTrav->ai_addr))->sin6_addr));
199 aiTrav = aiTrav->ai_next;
204 return (vIP.size() > 0);
207 bool LookupHost(
const char *pszName, std::vector<CNetAddr>& vIP,
unsigned int nMaxSolutions,
bool fAllowLookup)
209 std::string strHost(pszName);
212 if (boost::algorithm::starts_with(strHost,
"[") && boost::algorithm::ends_with(strHost,
"]"))
214 strHost = strHost.substr(1, strHost.size() - 2);
217 return LookupIntern(strHost.c_str(), vIP, nMaxSolutions, fAllowLookup);
220 bool LookupHostNumeric(
const char *pszName, std::vector<CNetAddr>& vIP,
unsigned int nMaxSolutions)
222 return LookupHost(pszName, vIP, nMaxSolutions,
false);
225 bool Lookup(
const char *pszName, std::vector<CService>& vAddr,
int portDefault,
bool fAllowLookup,
unsigned int nMaxSolutions)
229 int port = portDefault;
230 std::string hostname =
"";
233 std::vector<CNetAddr> vIP;
234 bool fRet = LookupIntern(hostname.c_str(), vIP, nMaxSolutions, fAllowLookup);
237 vAddr.resize(vIP.size());
238 for (
unsigned int i = 0; i < vIP.size(); i++)
243 bool Lookup(
const char *pszName,
CService& addr,
int portDefault,
bool fAllowLookup)
245 std::vector<CService> vService;
246 bool fRet =
Lookup(pszName, vService, portDefault, fAllowLookup, 1);
255 return Lookup(pszName, addr, portDefault,
false);
258 bool static Socks5(
string strDest,
int port,
SOCKET& hSocket)
260 LogPrintf(
"SOCKS5 connecting %s\n", strDest);
261 if (strDest.size() > 255)
264 return error(
"Hostname too long");
266 char pszSocks5Init[] =
"\5\1\0";
267 ssize_t nSize =
sizeof(pszSocks5Init) - 1;
269 ssize_t ret = send(hSocket, pszSocks5Init, nSize,
MSG_NOSIGNAL);
273 return error(
"Error sending to proxy");
276 if (recv(hSocket, pchRet1, 2, 0) != 2)
279 return error(
"Error reading proxy response");
281 if (pchRet1[0] != 0x05 || pchRet1[1] != 0x00)
284 return error(
"Proxy failed to initialize");
286 string strSocks5(
"\5\1");
287 strSocks5 +=
'\000'; strSocks5 +=
'\003';
288 strSocks5 +=
static_cast<char>(std::min((
int)strDest.size(), 255));
289 strSocks5 += strDest;
290 strSocks5 +=
static_cast<char>((port >> 8) & 0xFF);
291 strSocks5 +=
static_cast<char>((port >> 0) & 0xFF);
292 ret = send(hSocket, strSocks5.c_str(), strSocks5.size(),
MSG_NOSIGNAL);
293 if (ret != (ssize_t)strSocks5.size())
296 return error(
"Error sending to proxy");
299 if (recv(hSocket, pchRet2, 4, 0) != 4)
302 return error(
"Error reading proxy response");
304 if (pchRet2[0] != 0x05)
307 return error(
"Proxy failed to accept request");
309 if (pchRet2[1] != 0x00)
314 case 0x01:
return error(
"Proxy error: general failure");
315 case 0x02:
return error(
"Proxy error: connection not allowed");
316 case 0x03:
return error(
"Proxy error: network unreachable");
317 case 0x04:
return error(
"Proxy error: host unreachable");
318 case 0x05:
return error(
"Proxy error: connection refused");
319 case 0x06:
return error(
"Proxy error: TTL expired");
320 case 0x07:
return error(
"Proxy error: protocol error");
321 case 0x08:
return error(
"Proxy error: address type not supported");
322 default:
return error(
"Proxy error: unknown");
325 if (pchRet2[2] != 0x00)
328 return error(
"Error: malformed proxy response");
333 case 0x01: ret = recv(hSocket, pchRet3, 4, 0) != 4;
break;
334 case 0x04: ret = recv(hSocket, pchRet3, 16, 0) != 16;
break;
337 ret = recv(hSocket, pchRet3, 1, 0) != 1;
340 return error(
"Error reading from proxy");
342 int nRecv = pchRet3[0];
343 ret = recv(hSocket, pchRet3, nRecv, 0) != nRecv;
346 default:
closesocket(hSocket);
return error(
"Error: malformed proxy response");
351 return error(
"Error reading from proxy");
353 if (recv(hSocket, pchRet3, 2, 0) != 2)
356 return error(
"Error reading from proxy");
358 LogPrintf(
"SOCKS5 connected %s\n", strDest);
362 bool static ConnectSocketDirectly(
const CService &addrConnect,
SOCKET& hSocketRet,
int nTimeout)
366 struct sockaddr_storage sockaddr;
367 socklen_t len =
sizeof(sockaddr);
368 if (!addrConnect.
GetSockAddr((
struct sockaddr*)&sockaddr, &len)) {
369 LogPrintf(
"Cannot connect to %s: unsupported network\n", addrConnect.
ToString());
373 SOCKET hSocket = socket(((
struct sockaddr*)&sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP);
378 setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (
void*)&set,
sizeof(
int));
382 u_long fNonblock = 1;
383 if (ioctlsocket(hSocket, FIONBIO, &fNonblock) ==
SOCKET_ERROR)
385 int fFlags = fcntl(hSocket, F_GETFL, 0);
386 if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == -1)
393 if (connect(hSocket, (
struct sockaddr*)&sockaddr, len) ==
SOCKET_ERROR)
398 struct timeval timeout;
399 timeout.tv_sec = nTimeout / 1000;
400 timeout.tv_usec = (nTimeout % 1000) * 1000;
404 FD_SET(hSocket, &fdset);
405 int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout);
408 LogPrint(
"net",
"connection to %s timeout\n", addrConnect.
ToString());
418 socklen_t nRetSize =
sizeof(nRet);
420 if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, (
char*)(&nRet), &nRetSize) ==
SOCKET_ERROR)
422 if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) ==
SOCKET_ERROR)
453 if (ioctlsocket(hSocket, FIONBIO, &fNonblock) ==
SOCKET_ERROR)
455 fFlags = fcntl(hSocket, F_GETFL, 0);
456 if (fcntl(hSocket, F_SETFL, fFlags & ~O_NONBLOCK) ==
SOCKET_ERROR)
463 hSocketRet = hSocket;
468 assert(net >= 0 && net <
NET_MAX);
472 proxyInfo[net] = addrProxy;
477 assert(net >= 0 && net <
NET_MAX);
479 if (!proxyInfo[net].IsValid())
481 proxyInfoOut = proxyInfo[net];
489 nameProxy = addrProxy;
497 nameProxyOut = nameProxy;
508 for (
int i = 0; i <
NET_MAX; i++) {
516 bool static SetI2pSocketOptions(
SOCKET& hSocket)
522 setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (
void*)&set,
sizeof(
int));
526 u_long fNonblock = 1;
527 if (ioctlsocket(hSocket, FIONBIO, &fNonblock) ==
SOCKET_ERROR)
529 int fFlags = fcntl(hSocket, F_GETFL, 0);
530 if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == -1)
539 #endif // ENABLE_I2PSAM
546 if (addrDest.IsNativeI2P()) {
548 if( SetI2pSocketOptions(streamSocket) ) {
549 hSocketRet = streamSocket;
554 #endif // ENABLE_I2PSAM
558 return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout);
563 if (!ConnectSocketDirectly(proxy, hSocket, nTimeout))
569 hSocketRet = hSocket;
576 int port = portDefault;
595 if (!ConnectSocketDirectly(nameProxy, hSocket, nTimeout))
598 if (!Socks5(strDest, (
unsigned short)port, hSocket))
601 hSocketRet = hSocket;
607 memset(ip, 0,
sizeof(ip));
621 static const unsigned char pchOnionCat[] = {0xFD,0x87,0xD8,0x7E,0xEB,0x43};
644 #endif // ENABLE_I2PSAM
646 if (strName.size()>6 && strName.substr(strName.size() - 6, 6) ==
".onion") {
647 std::vector<unsigned char> vchAddr =
DecodeBase32(strName.substr(0, strName.size() - 6).c_str());
648 if (vchAddr.size() != 16-
sizeof(pchOnionCat))
650 memcpy(ip, pchOnionCat,
sizeof(pchOnionCat));
651 for (
unsigned int i=0; i<16-
sizeof(pchOnionCat); i++)
652 ip[i +
sizeof(pchOnionCat)] = vchAddr[i];
666 memcpy(ip+12, &ipv4Addr, 4);
674 memcpy(ip, &ipv6Addr, 16);
683 std::vector<CNetAddr> vIP;
691 std::vector<CNetAddr> vIP;
692 if (
LookupHost(strIp.c_str(), vIP, 1, fAllowLookup))
703 return (memcmp(ip, pchIPv4,
sizeof(pchIPv4)) == 0);
709 return (!IsIPv4() && !IsTor() && !IsNativeI2P());
710 #else // Original Code
711 return (!IsIPv4() && !IsTor());
719 (GetByte(3) == 192 && GetByte(2) == 168) ||
720 (GetByte(3) == 172 && (GetByte(2) >= 16 && GetByte(2) <= 31)));
725 return IsIPv4() && (GetByte(3) == 169 && GetByte(2) == 254);
730 return GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x0D && GetByte(12) == 0xB8;
735 return (GetByte(15) == 0x20 && GetByte(14) == 0x02);
740 static const unsigned char pchRFC6052[] = {0,0x64,0xFF,0x9B,0,0,0,0,0,0,0,0};
741 return (memcmp(ip, pchRFC6052,
sizeof(pchRFC6052)) == 0);
746 return (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0 && GetByte(12) == 0);
751 static const unsigned char pchRFC4862[] = {0xFE,0x80,0,0,0,0,0,0};
752 return (memcmp(ip, pchRFC4862,
sizeof(pchRFC4862)) == 0);
757 return ((GetByte(15) & 0xFE) == 0xFC);
762 static const unsigned char pchRFC6145[] = {0,0,0,0,0,0,0,0,0xFF,0xFF,0,0};
763 return (memcmp(ip, pchRFC6145,
sizeof(pchRFC6145)) == 0);
768 return (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x00 && (GetByte(12) & 0xF0) == 0x10);
773 return (memcmp(ip, pchOnionCat,
sizeof(pchOnionCat)) == 0);
777 bool CNetAddr::IsNativeI2P()
const
782 static const unsigned char pchAAAA[] = {
'A',
'A',
'A',
'A'};
786 std::string CNetAddr::GetI2PDestination()
const
790 #endif // ENABLE_I2PSAM
795 if (IsNativeI2P())
return false;
799 if (IsIPv4() && (GetByte(3) == 127 || GetByte(3) == 0))
803 static const unsigned char pchLocal[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
804 if (memcmp(ip, pchLocal, 16) == 0)
812 return (IsIPv4() && (GetByte(3) & 0xF0) == 0xE0)
813 || (GetByte(15) == 0xFF);
819 if (IsNativeI2P())
return true;
827 if (memcmp(ip, pchIPv4+3,
sizeof(pchIPv4)-3) == 0)
831 unsigned char ipNone[16] = {};
832 if (memcmp(ip, ipNone, 16) == 0)
842 uint32_t ipNone = INADDR_NONE;
843 if (memcmp(ip+12, &ipNone, 4) == 0)
848 if (memcmp(ip+12, &ipNone, 4) == 0)
858 return IsNativeI2P() || (IsValid() && !(IsRFC1918() || IsRFC3927() || IsRFC4862() || (IsRFC4193() && !IsTor()) || IsRFC4843() ||
IsLocal()));
859 #else // Original code
860 return IsValid() && !(IsRFC1918() || IsRFC3927() || IsRFC4862() || (IsRFC4193() && !IsTor()) || IsRFC4843() ||
IsLocal());
876 if (IsNativeI2P())
return NET_NATIVE_I2P;
886 return GetI2PDestination();
891 struct sockaddr_storage sockaddr;
892 socklen_t socklen =
sizeof(sockaddr);
893 if (serv.
GetSockAddr((
struct sockaddr*)&sockaddr, &socklen)) {
894 char name[1025] =
"";
895 if (!getnameinfo((
const struct sockaddr*)&sockaddr, socklen, name,
sizeof(name), NULL, 0, NI_NUMERICHOST))
896 return std::string(name);
899 return strprintf(
"%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0));
901 return strprintf(
"%x:%x:%x:%x:%x:%x:%x:%x",
902 GetByte(15) << 8 | GetByte(14), GetByte(13) << 8 | GetByte(12),
903 GetByte(11) << 8 | GetByte(10), GetByte(9) << 8 | GetByte(8),
904 GetByte(7) << 8 | GetByte(6), GetByte(5) << 8 | GetByte(4),
905 GetByte(3) << 8 | GetByte(2), GetByte(1) << 8 | GetByte(0));
917 #else // Use the original code
918 return (memcmp(a.
ip, b.
ip, 16) == 0);
926 #else // Use the original code
927 return (memcmp(a.
ip, b.
ip, 16) != 0);
935 #else // Use the original code
936 return (memcmp(a.
ip, b.
ip, 16) < 0);
944 memcpy(pipv4Addr, ip+12, 4);
951 if (IsNativeI2P())
return false;
953 memcpy(pipv6Addr, ip, 16);
961 std::vector<unsigned char> vchRet;
973 vchRet[0] = NET_NATIVE_I2P;
977 #endif // ENABLE_I2PSAM
994 else if (IsIPv4() || IsRFC6145() || IsRFC6052())
1000 else if (IsRFC3964())
1006 else if (IsRFC4380())
1009 vchRet.push_back(GetByte(3) ^ 0xFF);
1010 vchRet.push_back(GetByte(2) ^ 0xFF);
1020 else if (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
1026 vchRet.push_back(nClass);
1029 vchRet.push_back(GetByte(15 - nStartByte));
1034 vchRet.push_back(GetByte(15 - nStartByte) | ((1 << nBits) - 1));
1041 #ifdef ENABLE_I2PSAM
1043 #else // Use the original code
1047 memcpy(&nRet, &hash,
sizeof(nRet));
1053 LogPrintf(
"CNetAddr(%s)\n", ToString());
1058 static const int NET_UNKNOWN =
NET_MAX + 0;
1059 static const int NET_TEREDO =
NET_MAX + 1;
1060 int static GetExtNetwork(
const CNetAddr *addr)
1083 return REACH_UNREACHABLE;
1085 int ourNet = GetExtNetwork(
this);
1086 int theirNet = GetExtNetwork(paddrPartner);
1087 bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
1092 default:
return REACH_DEFAULT;
1097 default:
return REACH_DEFAULT;
1098 case NET_TEREDO:
return REACH_TEREDO;
1100 case NET_IPV6:
return fTunnel ? REACH_IPV6_WEAK : REACH_IPV6_STRONG;
1102 #ifdef ENABLE_I2PSAM
1103 case NET_NATIVE_I2P:
1105 default:
return REACH_UNREACHABLE;
1106 case NET_NATIVE_I2P:
return REACH_PRIVATE;
1111 default:
return REACH_DEFAULT;
1113 case NET_TOR:
return REACH_PRIVATE;
1117 default:
return REACH_DEFAULT;
1118 case NET_TEREDO:
return REACH_TEREDO;
1119 case NET_IPV6:
return REACH_IPV6_WEAK;
1126 default:
return REACH_DEFAULT;
1127 case NET_TEREDO:
return REACH_TEREDO;
1128 case NET_IPV6:
return REACH_IPV6_WEAK;
1130 case NET_TOR:
return REACH_PRIVATE;
1131 #ifdef ENABLE_I2PSAM
1132 case NET_NATIVE_I2P:
return REACH_UNREACHABLE;
1162 assert(addr.sin_family == AF_INET);
1167 assert(addr.sin6_family == AF_INET6);
1172 switch (paddr->sa_family) {
1174 *
this =
CService(*(
const struct sockaddr_in*)paddr);
1177 *
this =
CService(*(
const struct sockaddr_in6*)paddr);
1188 if (
Lookup(pszIpPort, ip, 0, fAllowLookup))
1196 if (
Lookup(pszIpPort, ip, portDefault, fAllowLookup))
1204 if (
Lookup(strIpPort.c_str(),
ip, 0, fAllowLookup))
1212 if (
Lookup(strIpPort.c_str(),
ip, portDefault, fAllowLookup))
1223 #ifdef ENABLE_I2PSAM
1225 #else // Use the original code
1232 #ifdef ENABLE_I2PSAM
1234 #else // Use the original code
1241 #ifdef ENABLE_I2PSAM
1243 #else // Use the original code
1251 if (*addrlen < (socklen_t)
sizeof(
struct sockaddr_in))
1253 *addrlen =
sizeof(
struct sockaddr_in);
1254 struct sockaddr_in *paddrin = (
struct sockaddr_in*)paddr;
1255 memset(paddrin, 0, *addrlen);
1258 paddrin->sin_family = AF_INET;
1259 paddrin->sin_port = htons(port);
1263 if (*addrlen < (socklen_t)
sizeof(
struct sockaddr_in6))
1265 *addrlen =
sizeof(
struct sockaddr_in6);
1266 struct sockaddr_in6 *paddrin6 = (
struct sockaddr_in6*)paddr;
1267 memset(paddrin6, 0, *addrlen);
1270 paddrin6->sin6_family = AF_INET6;
1271 paddrin6->sin6_port = htons(port);
1279 std::vector<unsigned char> vKey;
1280 #ifdef ENABLE_I2PSAM
1290 vKey[16] = port / 0x100;
1291 vKey[17] = port & 0x0FF;
1300 #ifdef ENABLE_I2PSAM
1301 std::string CService::ToStringI2pPort()
const
1303 if( IsNativeI2P() ) {
1306 std::string samPort =
strprintf(
"%u",
GetArg(
"-i2p.options.samport",
"7656") );
1310 return "Unknown address";
1312 #endif // ENABLE_I2PSAM
1316 #ifdef ENABLE_I2PSAM
1345 if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
1346 NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1347 buf,
sizeof(buf), NULL))
1353 return strprintf(
"Unknown error (%d)", err);
1360 const char *s = buf;
1364 #ifdef STRERROR_R_CHAR_P
1365 s = strerror_r(err, buf,
sizeof(buf));
1367 (void) strerror_r(err, buf,
sizeof(buf));
std::string namingLookup(const std::string &name) const
unsigned short GetPort() const
void SetIP(const CNetAddr &ip)
bool operator<(const CNetAddr &a, const CNetAddr &b)
std::string ToStringIP() const
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
bool isValidI2pAddress(const std::string &I2pAddr)
static SAM::StreamSessionAdapter & Instance()
std::string ToStringIPPort() const
std::string B32AddressFromDestination(const std::string &destination)
void SetPort(unsigned short portIn)
bool LookupNumeric(const char *pszName, CService &addr, int portDefault)
bool ConnectSocketByName(CService &addr, SOCKET &hSocketRet, const char *pszDest, int portDefault, int nTimeout)
#define WSAGetLastError()
unsigned int GetByte(int n) const
SAM::SOCKET connect(const std::string &destination, bool silent)
bool SetNameProxy(CService addrProxy)
bool isValidI2pB32(const std::string &B32Address)
bool operator==(const CNetAddr &a, const CNetAddr &b)
int GetReachabilityFrom(const CNetAddr *paddrPartner=NULL) const
Calculates a metric for how reachable (*this) is from a given partner.
enum Network ParseNetwork(std::string net)
A combination of a network address (CNetAddr) and a (TCP) port.
bool IsProxy(const CNetAddr &addr)
#define NATIVE_I2P_DESTINATION_SIZE
string EncodeBase32(const unsigned char *pch, size_t len)
bool ConnectSocket(const CService &addrDest, SOCKET &hSocketRet, int nTimeout)
std::string ToString() const
uint256 Hash(const T1 pbegin, const T1 pend)
bool GetInAddr(struct in_addr *pipv4Addr) const
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
std::vector< unsigned char > GetGroup() const
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid)
void * memcpy(void *a, const void *b, size_t c)
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
bool operator!=(const CNetAddr &a, const CNetAddr &b)
bool SetSpecial(const std::string &strName)
Returns TRUE if the address name can be looked up and resolved.
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
std::string ToString() const
std::string ToStringPort() const
std::string GetNetworkName(enum Network net)
bool LookupHost(const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
bool SetSockAddr(const struct sockaddr *paddr)
bool GetNameProxy(CService &nameProxyOut)
bool SetProxy(enum Network net, CService addrProxy)
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
bool LookupHostNumeric(const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions)
bool IsLocal(const CService &addr)
check whether a given address is potentially local
std::vector< unsigned char > GetKey() const
enum Network GetNetwork() const