Skip to content

Commit a0e6eb6

Browse files
committed
internet: remove Ipv4InterfaceAddress::SetBroadcast and optimize the broadcast address handling
1 parent b71b491 commit a0e6eb6

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This file is a best-effort approach to solving this issue; we will do our best b
3030
* 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.
3131
* (network): The address class comparison is now based on std::strong_ordering operator<=> comparison operator.
3232
* (network): An empty (uninitialized) Address is now printed as "00-00:00".
33+
* (internet): The function `Ipv4InterfaceAddress::SetBroadcast` has been removed from the codebase because the broadcast address must be built from the IP address and mask.
3334

3435
### Changes to build system
3536

src/internet/model/ipv4-interface-address.cc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ Ipv4InterfaceAddress::Ipv4InterfaceAddress(Ipv4Address local, Ipv4Mask mask)
3434
m_scope = HOST;
3535
}
3636
m_mask = mask;
37-
m_broadcast = Ipv4Address(local.Get() | (~mask.Get()));
3837
}
3938

4039
Ipv4InterfaceAddress::Ipv4InterfaceAddress(const Ipv4InterfaceAddress& o)
4140
: m_local(o.m_local),
4241
m_mask(o.m_mask),
43-
m_broadcast(o.m_broadcast),
4442
m_scope(o.m_scope),
4543
m_secondary(o.m_secondary)
4644
{
@@ -87,18 +85,11 @@ Ipv4InterfaceAddress::GetMask() const
8785
return m_mask;
8886
}
8987

90-
void
91-
Ipv4InterfaceAddress::SetBroadcast(Ipv4Address broadcast)
92-
{
93-
NS_LOG_FUNCTION(this << broadcast);
94-
m_broadcast = broadcast;
95-
}
96-
9788
Ipv4Address
9889
Ipv4InterfaceAddress::GetBroadcast() const
9990
{
10091
NS_LOG_FUNCTION(this);
101-
return m_broadcast;
92+
return Ipv4Address(m_local.Get() | (~m_mask.Get()));
10293
}
10394

10495
void

src/internet/model/ipv4-interface-address.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,13 @@ class Ipv4InterfaceAddress
101101
* @param mask the network mask
102102
*/
103103
void SetMask(Ipv4Mask mask);
104+
104105
/**
105106
* @brief Get the network mask
106107
* @returns the network mask
107108
*/
108109
Ipv4Mask GetMask() const;
109-
/**
110-
* @brief Set the broadcast address
111-
* @param broadcast the broadcast address
112-
*/
113-
void SetBroadcast(Ipv4Address broadcast);
110+
114111
/**
115112
* @brief Get the broadcast address
116113
* @returns the broadcast address
@@ -157,8 +154,7 @@ class Ipv4InterfaceAddress
157154
Ipv4Address m_local; //!< Interface address
158155
// Note: m_peer may be added in future when necessary
159156
// Ipv4Address m_peer; // Peer destination address (in Linux: m_address)
160-
Ipv4Mask m_mask; //!< Network mask
161-
Ipv4Address m_broadcast; //!< Broadcast address
157+
Ipv4Mask m_mask; //!< Network mask
162158

163159
InterfaceAddressScope_e m_scope; //!< Address scope
164160
bool m_secondary; //!< For use in multihoming
@@ -194,15 +190,15 @@ std::ostream& operator<<(std::ostream& os, const Ipv4InterfaceAddress& addr);
194190
inline bool
195191
operator==(const Ipv4InterfaceAddress& a, const Ipv4InterfaceAddress& b)
196192
{
197-
return (a.m_local == b.m_local && a.m_mask == b.m_mask && a.m_broadcast == b.m_broadcast &&
198-
a.m_scope == b.m_scope && a.m_secondary == b.m_secondary);
193+
return (a.m_local == b.m_local && a.m_mask == b.m_mask && a.m_scope == b.m_scope &&
194+
a.m_secondary == b.m_secondary);
199195
}
200196

201197
inline bool
202198
operator!=(const Ipv4InterfaceAddress& a, const Ipv4InterfaceAddress& b)
203199
{
204-
return (a.m_local != b.m_local || a.m_mask != b.m_mask || a.m_broadcast != b.m_broadcast ||
205-
a.m_scope != b.m_scope || a.m_secondary != b.m_secondary);
200+
return (a.m_local != b.m_local || a.m_mask != b.m_mask || a.m_scope != b.m_scope ||
201+
a.m_secondary != b.m_secondary);
206202
}
207203

208204
} // namespace ns3

0 commit comments

Comments
 (0)