Added a new constructor taking a string and port number (including
test cases) - mostly useful for debugging.
This commit is contained in:
parent
6490551533
commit
b4107bfc25
@ -203,4 +203,17 @@ void TransportAddress::unitTesting()
|
|||||||
assert(t17.getIP() == (128u << 24));
|
assert(t17.getIP() == (128u << 24));
|
||||||
assert(!t17.isLAN());
|
assert(!t17.isLAN());
|
||||||
|
|
||||||
|
// Test constructors
|
||||||
|
TransportAddress t18("128.0.0.0");
|
||||||
|
assert(t18.getIP() == (128u << 24));
|
||||||
|
assert(t18.getPort() == 0);
|
||||||
|
|
||||||
|
TransportAddress t19("128.0.0.0:1");
|
||||||
|
assert(t19.getIP() == (128u << 24));
|
||||||
|
assert(t19.getPort() == 1);
|
||||||
|
|
||||||
|
TransportAddress t20("128.0.0.0", 123);
|
||||||
|
assert(t20.getIP() == (128u << 24));
|
||||||
|
assert(t20.getPort() == 123);
|
||||||
|
|
||||||
} // unitTesting
|
} // unitTesting
|
||||||
|
@ -58,7 +58,21 @@ public:
|
|||||||
} // TransportAddress(EnetAddress)
|
} // TransportAddress(EnetAddress)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Construct an IO address from a string in the format x.x.x.x:xxx. */
|
/** Construct an IO address from a string in the format x.x.x.x with a
|
||||||
|
* port number. */
|
||||||
|
TransportAddress(const std::string& str, uint16_t port_number)
|
||||||
|
{
|
||||||
|
std::vector<uint32_t> ip = StringUtils::splitToUInt(str, '.');
|
||||||
|
m_ip = 0;
|
||||||
|
m_port = 0;
|
||||||
|
if (ip.size() >= 4)
|
||||||
|
m_ip = (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
|
||||||
|
|
||||||
|
m_port = port_number;
|
||||||
|
} // TransportAddress(string of ip, port number)
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Construct an IO address from a string in the format x.x.x.x:x. */
|
||||||
TransportAddress(const std::string& str)
|
TransportAddress(const std::string& str)
|
||||||
{
|
{
|
||||||
std::string combined = StringUtils::replace(str, ":", ".");
|
std::string combined = StringUtils::replace(str, ":", ".");
|
||||||
|
Loading…
Reference in New Issue
Block a user