diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2011-05-02 15:34:42 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2011-05-10 23:49:30 +0200 |
commit | a6a5bb7c204130dd4f3ced74446798eb67ea6472 (patch) | |
tree | 83d8c791956b4027fa9c63c05b670527c8755ab8 /src/irc.cpp | |
parent | 04a667b0767a6c3fff8d24be784ccaec9edf712b (diff) |
Support for name lookups in -connect and -addnode
* A new option -dns is introduced that enables name lookups in
-connect and -addnode, which is not enabled by default,
as it may be considered a security issue.
* A Lookup function is added that supports retrieving one or
more addresses based on a host name
* CAddress constructors (optionally) support name lookups.
* The different places in the source code that did name lookups
are refactored to use NameLookup or CAddress instead (dns seeding,
irc server lookup, getexternalip, ...).
* Removed ToStringLog() from CAddress, and switched to ToString(),
since it was empty.
Diffstat (limited to 'src/irc.cpp')
-rw-r--r-- | src/irc.cpp | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/src/irc.cpp b/src/irc.cpp index 5adaf11658..4e39889245 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -41,7 +41,7 @@ bool DecodeAddress(string str, CAddress& addr) return false; memcpy(&tmp, &vch[0], sizeof(tmp)); - addr = CAddress(tmp.ip, tmp.port, NODE_NETWORK); + addr = CAddress(tmp.ip, ntohs(tmp.port), NODE_NETWORK); return true; } @@ -215,25 +215,15 @@ bool GetIPFromIRC(SOCKET hSocket, string strMyName, unsigned int& ipRet) return false; string strHost = str.substr(str.rfind("@")+1); - unsigned int a=0, b=0, c=0, d=0; - if (sscanf(strHost.c_str(), "%u.%u.%u.%u", &a, &b, &c, &d) == 4 && - inet_addr(strHost.c_str()) != INADDR_NONE) - { - printf("GetIPFromIRC() userhost is IP %s\n", strHost.c_str()); - ipRet = CAddress(strHost).ip; - } - else - { - // Hybrid IRC used by lfnet always returns IP when you userhost yourself, - // but in case another IRC is ever used this should work. - printf("GetIPFromIRC() got userhost %s\n", strHost.c_str()); - if (fUseProxy) - return false; - struct hostent* phostent = gethostbyname(strHost.c_str()); - if (!phostent || !phostent->h_addr_list || !phostent->h_addr_list[0]) - return false; - ipRet = *(u_long*)phostent->h_addr_list[0]; - } + // Hybrid IRC used by lfnet always returns IP when you userhost yourself, + // but in case another IRC is ever used this should work. + printf("GetIPFromIRC() got userhost %s\n", strHost.c_str()); + if (fUseProxy) + return false; + CAddress addr(strHost, 0, true); + if (!addr.IsValid()) + return false; + ipRet = addr.ip; return true; } @@ -276,9 +266,9 @@ void ThreadIRCSeed2(void* parg) if (!fTOR) { //struct hostent* phostent = gethostbyname("chat.freenode.net"); - struct hostent* phostent = gethostbyname("irc.lfnet.org"); - if (phostent && phostent->h_addr_list && phostent->h_addr_list[0]) - addrConnect = CAddress(*(u_long*)phostent->h_addr_list[0], htons(6667)); + CAddress addrIRC("irc.lfnet.org:6667", 0, true); + if (addrIRC.IsValid()) + addrConnect = addrIRC; } SOCKET hSocket; @@ -390,7 +380,7 @@ void ThreadIRCSeed2(void* parg) { addr.nTime = GetAdjustedTime(); if (AddAddress(addr, 51 * 60)) - printf("IRC got new address\n"); + printf("IRC got new address: %s\n", addr.ToString().c_str()); nGotIRCAddresses++; } else |