summaryrefslogtreecommitdiff
path: root/AK/IPv4Address.h
diff options
context:
space:
mode:
authorMaciej <sppmacd@pm.me>2022-03-26 10:35:52 +0100
committerSam Atkins <atkinssj@gmail.com>2022-07-09 09:22:25 +0100
commit36676a1604de8b5868d4d9b154342a8349b50035 (patch)
tree8738c90e5e7b3a0fe0a44428d1191e8393963163 /AK/IPv4Address.h
parentb85666b3d203bb39e75da8d582e428800f4cb26c (diff)
downloadserenity-36676a1604de8b5868d4d9b154342a8349b50035.zip
AK: Add IPv4Address::netmask_from_cidr
Diffstat (limited to 'AK/IPv4Address.h')
-rw-r--r--AK/IPv4Address.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h
index 8f72f8d3a0..d52996a9c9 100644
--- a/AK/IPv4Address.h
+++ b/AK/IPv4Address.h
@@ -119,6 +119,13 @@ public:
return IPv4Address(a, b, c, d);
}
+ static constexpr IPv4Address netmask_from_cidr(int cidr)
+ {
+ VERIFY(cidr >= 0 && cidr <= 32);
+ u32 value = 0xffffffffull << (32 - cidr);
+ return IPv4Address((value & 0xff000000) >> 24, (value & 0xff0000) >> 16, (value & 0xff00) >> 8, (value & 0xff));
+ }
+
constexpr in_addr_t to_in_addr_t() const { return m_data; }
constexpr u32 to_u32() const { return m_data; }