Skip to content

Commit 2493d22

Browse files
committed
Tom's comments
1 parent 28ec02d commit 2493d22

File tree

7 files changed

+20
-28
lines changed

7 files changed

+20
-28
lines changed

CHANGES.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ This file is a best-effort approach to solving this issue; we will do our best b
2626
to the new `Rx` trace signature or instead use the same trace sink function or method with the
2727
the `SinkApplication::RxWithoutAddress` trace.
2828
* Initializing a Ipv[4,6]Address from a string using the constructor or the `Set` function will result in a crash if the string can not be parsed as an IPv4 or IPv6 address.
29-
* The `Ipv[4,6]Address::IsInitialized()` function has been deprecated and returns always `true`.
30-
* A new static function `Ipv[4,6]Address::IsCompatible()` has been added to safely check if a string can be parsed as an IPv4 or IPv6 address.
31-
* The default value for `Ipv4Address` is now "0.0.0.0", which is consistent with RFC 1122.
29+
* The `Ipv[4,6]Address::IsInitialized()` function has been deprecated and returns always `true`. The default value of Ipv4Address created with the constructor that takes no arguments is 0.0.0.0 (previously, it was 102.102.102.102), and an Ipv4Address instance can be checked against that unspecified address value (or use std::optional to denote an address that has not been set yet).
30+
* A new static function `Ipv[4,6]Address::CheckCompatible()` has been added to safely check if a string can be parsed as an IPv4 or IPv6 address.
3231

3332
### Changes to build system
3433

src/internet-apps/examples/ping-example.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ main(int argc, char* argv[])
115115

116116
if (!destinationStr.empty())
117117
{
118-
if (Ipv4Address::IsCompatible(destinationStr))
118+
if (Ipv4Address::CheckCompatible(destinationStr))
119119
{
120120
v4Dst = Ipv4Address(destinationStr.c_str());
121121
useIpv6 = false;
122122
destination = v4Dst.value();
123123
}
124-
else if (Ipv6Address::IsCompatible(destinationStr))
124+
else if (Ipv6Address::CheckCompatible(destinationStr))
125125
{
126126
v6Dst = Ipv6Address(destinationStr.c_str());
127127
useIpv6 = true;
@@ -135,13 +135,13 @@ main(int argc, char* argv[])
135135

136136
if (!sourceStr.empty())
137137
{
138-
if (Ipv4Address::IsCompatible(sourceStr))
138+
if (Ipv4Address::CheckCompatible(sourceStr))
139139
{
140140
v4Src = Ipv4Address(sourceStr.c_str());
141141
useIpv6 = false;
142142
source = v4Src.value();
143143
}
144-
else if (Ipv6Address::IsCompatible(sourceStr))
144+
else if (Ipv6Address::CheckCompatible(sourceStr))
145145
{
146146
v6Src = Ipv6Address(sourceStr.c_str());
147147
useIpv6 = true;

src/internet/test/ipv4-address-helper-test-suite.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ AddressAllocatorHelperTestCase::DoTeardown()
9494
void
9595
AddressAllocatorHelperTestCase::DoRun()
9696
{
97-
Ipv4Address network;
9897
Ipv4Address address;
9998
Ipv4AddressHelper h;
10099

src/network/utils/ipv4-address.cc

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,6 @@ Ipv4Mask::GetPrefixLength() const
136136
return tmp;
137137
}
138138

139-
/**
140-
* Value of a not-yet-initialized IPv4 address, corresponding to 0.0.0.0.
141-
* See also \RFC{1122}
142-
*/
143-
static constexpr uint32_t UNINITIALIZED = 0x00000000U;
144-
145-
Ipv4Address::Ipv4Address()
146-
: m_address(UNINITIALIZED)
147-
{
148-
NS_LOG_FUNCTION(this);
149-
}
150-
151139
Ipv4Address::Ipv4Address(uint32_t address)
152140
{
153141
NS_LOG_FUNCTION(this << address);
@@ -167,15 +155,15 @@ Ipv4Address::Ipv4Address(const char* address)
167155
}
168156

169157
bool
170-
Ipv4Address::IsCompatible(const std::string& addressStr)
158+
Ipv4Address::CheckCompatible(const std::string& addressStr)
171159
{
172160
NS_LOG_FUNCTION(addressStr);
173161

174162
uint32_t buffer;
175163

176164
if (inet_pton(AF_INET, addressStr.c_str(), &buffer) <= 0)
177165
{
178-
NS_LOG_LOGIC("Error, can not build an IPv4 address from an invalid string: " << addressStr);
166+
NS_LOG_WARN("Error, can not build an IPv4 address from an invalid string: " << addressStr);
179167
return false;
180168
}
181169
return true;

src/network/utils/ipv4-address.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Ipv4Mask;
3131
class Ipv4Address
3232
{
3333
public:
34-
Ipv4Address();
34+
Ipv4Address() = default;
3535
/**
3636
* input address is in host order.
3737
* @param address The host order 32-bit address
@@ -59,10 +59,13 @@ class Ipv4Address
5959
*
6060
* Note: the function uses ``inet_pton`` internally.
6161
*
62+
* @see Address::CheckCompatible hich has a similar name but which
63+
* instead checks the underlying type and length embedded in the Address.
64+
*
6265
* @param addressStr string containing the address as described above
6366
* @return true if the string can be parsed as an IPv4 address
6467
*/
65-
static bool IsCompatible(const std::string& addressStr);
68+
static bool CheckCompatible(const std::string& addressStr);
6669
/**
6770
* Get the host-order 32-bit IP address
6871
* @return the host-order 32-bit IP address
@@ -226,7 +229,7 @@ class Ipv4Address
226229
* @returns the address type
227230
*/
228231
static uint8_t GetType();
229-
uint32_t m_address; //!< IPv4 address
232+
uint32_t m_address{0}; //!< IPv4 address
230233

231234
/**
232235
* @brief Equal to operator.

src/network/utils/ipv6-address.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ Ipv6Address::Ipv6Address(const char* address)
174174
}
175175

176176
bool
177-
Ipv6Address::IsCompatible(const std::string& addressStr)
177+
Ipv6Address::CheckCompatible(const std::string& addressStr)
178178
{
179179
NS_LOG_FUNCTION(addressStr);
180180

181181
uint8_t buffer[16];
182182

183183
if (inet_pton(AF_INET6, addressStr.c_str(), &buffer) <= 0)
184184
{
185-
NS_LOG_LOGIC("Error, can not build an IPv6 address from an invalid string: " << addressStr);
185+
NS_LOG_WARN("Error, can not build an IPv6 address from an invalid string: " << addressStr);
186186
return false;
187187
}
188188
return true;

src/network/utils/ipv6-address.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ class Ipv6Address
5757
*
5858
* Note: the function uses ``inet_pton`` internally.
5959
*
60+
* @see Address::CheckCompatible hich has a similar name but which
61+
* instead checks the underlying type and length embedded in the Address.
62+
*
6063
* @param addressStr string containing the address as described above
6164
* @return true if the string can be parsed as an IPv6 address
6265
*/
63-
static bool IsCompatible(const std::string& addressStr);
66+
static bool CheckCompatible(const std::string& addressStr);
6467

6568
/**
6669
* @brief Constructs an Ipv6Address by using the input 16 bytes.

0 commit comments

Comments
 (0)