From a2518740ae26c8cfcf9952322a8cd1b93889efd2 Mon Sep 17 00:00:00 2001 From: Yifan Gu Date: Sat, 25 Nov 2023 06:58:55 +0000 Subject: [PATCH] add routines for checking broadcast and multicast --- src/ip.cpp | 6 ++++++ src/ip.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/ip.cpp b/src/ip.cpp index daed37c..896b2ea 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -34,6 +34,12 @@ namespace lpvpn::ip { } return ret; } + bool Address4::isBroadcast() const { + return toUint32() == 0xFFFFFFFF; + } + bool Address4::isMulticast() const { + return (addr[0] & 0xF0) == 0xE0; + } bool Address4::operator==(const Address4& other) const { return addr == other.addr; } diff --git a/src/ip.h b/src/ip.h index 0fcc3c0..2c3655b 100644 --- a/src/ip.h +++ b/src/ip.h @@ -25,6 +25,8 @@ namespace lpvpn::ip { Address4(uint32_t addr); ~Address4(); uint32_t toUint32() const; + bool isBroadcast() const; + bool isMulticast() const; bool operator==(const Address4& other) const; Address4 operator+(uint32_t other) const; Address4 operator-(uint32_t other) const;