Bug 2176 - Building IPv4 address from char* doesn't look reliable

This commit is contained in:
Sébastien Deronne
2015-11-07 23:37:44 +01:00
parent a73970b783
commit 7cc8b40f88
2 changed files with 14 additions and 5 deletions

View File

@@ -45,6 +45,7 @@ Bugs fixed
- Bug 2041 - TCP RTO needs unit tests
- Bug 2150 - The TCP sender keeps retransmitting and does not terminate the connection after some retries.
- Bug 2159 - TCP advertises wrong receive window
- Bug 2176 - Building IPv4 address from char* doesn't look reliable
- Bug 2183 - LiIonEnergySourceHelper is not in the energy wscript
- Bug 2185 - WiFi MacLow may respond to errored frames that it should ignore
- Bug 2195 - Udp[*]Client can't send packets to broadcast address

View File

@@ -41,23 +41,31 @@ AsciiToIpv4Host (char const *address)
{
NS_LOG_FUNCTION (&address);
uint32_t host = 0;
uint8_t numberOfDots = 0;
char const *ptr = address;
NS_ASSERT_MSG (*ptr != ASCII_DOT, "Error, can not build an IPv4 address from an invalid string: " << address);
while (true)
{
uint8_t byte = 0;
while (*address != ASCII_DOT && *address != 0)
while (*ptr != ASCII_DOT && *ptr != 0)
{
byte *= 10;
byte += *address - ASCII_ZERO;
address++;
byte += *ptr - ASCII_ZERO;
ptr++;
}
host <<= 8;
host |= byte;
if (*address == 0)
if (*ptr == 0)
{
break;
}
address++;
ptr++;
numberOfDots ++;
}
NS_ASSERT_MSG (*(ptr-1) != ASCII_DOT, "Error, can not build an IPv4 address from an invalid string: " << address);
NS_ASSERT_MSG (numberOfDots == 3, "Error, can not build an IPv4 address from an invalid string: " << address);
return host;
}