aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-05-11 15:28:59 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-05-11 15:29:20 +0200
commit8f10a2889089af1b2ac64802360494b54c8c7ff1 (patch)
tree06df6b9e6114b170fca7aaa7e205c26207a0ab2f /src/init.cpp
parent7fa4443f77a659031e277337770b506fcf954d69 (diff)
Separate listening sockets, -bind=<addr>
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 202d513677..877b1d471f 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -119,6 +119,18 @@ bool AppInit(int argc, char* argv[])
return fRet;
}
+bool static Bind(const CService &addr) {
+ if (IsLimited(addr))
+ return false;
+ std::string strError;
+ if (!BindListenPort(addr, strError))
+ {
+ ThreadSafeMessageBox(strError, _("Bitcoin"), wxOK | wxMODAL);
+ return false;
+ }
+ return true;
+}
+
bool AppInit2(int argc, char* argv[])
{
#ifdef _MSC_VER
@@ -193,6 +205,7 @@ bool AppInit2(int argc, char* argv[])
" -discover \t " + _("Try to discover public IP address (default: 1)") + "\n" +
" -irc \t " + _("Find peers using internet relay chat (default: 0)") + "\n" +
" -listen \t " + _("Accept connections from outside (default: 1)") + "\n" +
+ " -bind=<addr> \t " + _("Bind to given address. Use [host]:port notation for IPv6") + "\n" +
#ifdef QT_GUI
" -lang=<lang> \t\t " + _("Set language, for example \"de_DE\" (default: system locale)") + "\n" +
#endif
@@ -548,7 +561,11 @@ bool AppInit2(int argc, char* argv[])
if (mapArgs.count("-connect"))
SoftSetBoolArg("-dnsseed", false);
-
+
+ // even in Tor mode, if -bind is specified, you really want -listen
+ if (mapArgs.count("-bind"))
+ SoftSetBoolArg("-listen", true);
+
bool fTor = (fUseProxy && addrProxy.GetPort() == 9050);
if (fTor)
{
@@ -588,14 +605,23 @@ bool AppInit2(int argc, char* argv[])
const char* pszP2SH = "/P2SH/";
COINBASE_FLAGS << std::vector<unsigned char>(pszP2SH, pszP2SH+strlen(pszP2SH));
+ bool fBound = false;
if (!fNoListen)
{
std::string strError;
- if (!BindListenPort(strError))
- {
- ThreadSafeMessageBox(strError, _("Bitcoin"), wxOK | wxMODAL);
- return false;
+ if (mapArgs.count("-bind")) {
+ BOOST_FOREACH(std::string strBind, mapMultiArgs["-bind"]) {
+ fBound |= Bind(CService(strBind, GetDefaultPort(), false));
+ }
+ } else {
+ struct in_addr inaddr_any = {s_addr: INADDR_ANY};
+ fBound |= Bind(CService(inaddr_any, GetDefaultPort()));
+#ifdef USE_IPV6
+ fBound |= Bind(CService(in6addr_any, GetDefaultPort()));
+#endif
}
+ if (!fBound)
+ return false;
}
if (mapArgs.count("-externalip"))