diff options
author | Maciej <sppmacd@pm.me> | 2022-03-26 10:35:52 +0100 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-07-09 09:22:25 +0100 |
commit | 36676a1604de8b5868d4d9b154342a8349b50035 (patch) | |
tree | 8738c90e5e7b3a0fe0a44428d1191e8393963163 /AK/IPv4Address.h | |
parent | b85666b3d203bb39e75da8d582e428800f4cb26c (diff) | |
download | serenity-36676a1604de8b5868d4d9b154342a8349b50035.zip |
AK: Add IPv4Address::netmask_from_cidr
Diffstat (limited to 'AK/IPv4Address.h')
-rw-r--r-- | AK/IPv4Address.h | 7 |
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; } |