diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-04-21 10:45:08 -0400 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2011-05-15 12:36:21 -0400 |
commit | 00bcfe0b7ec203462f774a216db9fb25436e02ef (patch) | |
tree | ecb9b4f1f655fb72381d739f14054eb59fe5cc35 /src/net.cpp | |
parent | c22feee634ade7f887d7e29635a8e5dc44675273 (diff) |
-port option to listen on arbitrary port
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/net.cpp b/src/net.cpp index 018afc47c7..9211c36693 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -53,6 +53,10 @@ CAddress addrProxy("127.0.0.1",9050); +unsigned short GetListenPort() +{ + return (unsigned short)(GetArg("-port", GetDefaultPort())); +} void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd) { @@ -962,7 +966,7 @@ void ThreadMapPort2(void* parg) printf("ThreadMapPort started\n"); char port[6]; - sprintf(port, "%d", GetDefaultPort()); + sprintf(port, "%d", GetListenPort()); const char * rootdescurl = 0; const char * multicastif = 0; @@ -1432,14 +1436,11 @@ void ThreadMessageHandler2(void* parg) - - - bool BindListenPort(string& strError) { strError = ""; int nOne = 1; - addrLocalHost.port = htons(GetDefaultPort()); + addrLocalHost.port = htons(GetListenPort()); #ifdef __WXMSW__ // Initialize Windows Sockets @@ -1491,7 +1492,7 @@ bool BindListenPort(string& strError) memset(&sockaddr, 0, sizeof(sockaddr)); sockaddr.sin_family = AF_INET; sockaddr.sin_addr.s_addr = INADDR_ANY; // bind to all IPs on this computer - sockaddr.sin_port = htons(GetDefaultPort()); + sockaddr.sin_port = htons(GetListenPort()); if (::bind(hListenSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR) { int nErr = WSAGetLastError(); @@ -1553,7 +1554,7 @@ void StartNode(void* parg) printf("ipv4 %s: %s\n", ifa->ifa_name, pszIP); // Take the first IP that isn't loopback 127.x.x.x - CAddress addr(*(unsigned int*)&s4->sin_addr, 0, nLocalServices); + CAddress addr(*(unsigned int*)&s4->sin_addr, GetListenPort(), nLocalServices); if (addr.IsValid() && addr.GetByte(3) != 127) { addrLocalHost = addr; |