Skip to content

Commit a3ec4ec

Browse files
committed
network: add a function to detect IPv4 APIPA addresses
1 parent d69522a commit a3ec4ec

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This file is a best-effort approach to solving this issue; we will do our best b
1616

1717
### New API
1818

19+
* (network) Added a function to detect IPv4 APIPA addresses (169.254.0.0/16).
20+
1921
### Changes to existing API
2022

2123
* (internet-apps) Added a parameter to the RADVD helper to announce a prefix without the autoconfiguration flag.

src/network/utils/ipv4-address.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ Ipv4Address::IsLocalMulticast() const
281281
return (m_address & 0xffffff00) == 0xe0000000;
282282
}
283283

284+
bool
285+
Ipv4Address::IsLinkLocal() const
286+
{
287+
NS_LOG_FUNCTION(this);
288+
// Link-Local address is 169.254.0.0/16
289+
return (m_address & 0xffff0000) == 0xa9fe0000;
290+
}
291+
284292
void
285293
Ipv4Address::Serialize(uint8_t buf[4]) const
286294
{

src/network/utils/ipv4-address.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ class Ipv4Address
112112
* @return true only if address is in local multicast address scope, 224.0.0.0/24
113113
*/
114114
bool IsLocalMulticast() const;
115+
/**
116+
* @brief If the IPv4 address is an APIPA address (169.254/16).
117+
*
118+
* The Automatic Private IP Address is described in \RFC{3927}
119+
*
120+
* @return true if the address is link-local, false otherwise
121+
*/
122+
bool IsLinkLocal() const;
115123
/**
116124
* @brief Combine this address with a network mask
117125
*

0 commit comments

Comments
 (0)