Browse Source

Add IPv4 address assignment to ffffffffffffffff test network.

Adam Ierymenko 10 years ago
parent
commit
3f15752f73
1 changed files with 9 additions and 0 deletions
  1. 9 0
      node/NetworkConfig.cpp

+ 9 - 0
node/NetworkConfig.cpp

@@ -25,6 +25,8 @@
  * LLC. Start here: http://www.zerotier.com/
  */
 
+#include <stdint.h>
+
 #include "NetworkConfig.hpp"
 #include "Utils.hpp"
 
@@ -51,6 +53,13 @@ SharedPtr<NetworkConfig> NetworkConfig::createTestNetworkConfig(const Address &s
 	nc->_name = "ZT_TEST_NETWORK";
 	nc->_description = "Built-in dummy test network";
 
+	// Make up a V4 IP from 'self' in the 10.0.0.0/8 range -- no
+	// guarantee of uniqueness but collisions are unlikely.
+	uint32_t ip = (uint32_t)((self.toInt() & 0x00ffffff) | 0x0a000000); // 10.x.x.x
+	if ((ip & 0x000000ff) == 0x000000ff) ip ^= 0x00000001; // but not ending in .255
+	if ((ip & 0x000000ff) == 0x00000000) ip ^= 0x00000001; // or .0
+	nc->_staticIps.push_back(InetAddress(Utils::hton(ip),8));
+
 	return nc;
 }