summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@anytun.org>2008-02-27 19:53:34 +0000
committerOthmar Gsenger <otti@anytun.org>2008-02-27 19:53:34 +0000
commitff454b083ca534ef8a21db99a209bd494eaa72b6 (patch)
tree8c93b8ad45efdc712493ffb714b91e14d38ee25f
parentadded networkAddress operators (diff)
added networkprefix auto detectio9n of network address
-rw-r--r--networkAddress.cpp20
-rw-r--r--networkAddress.h5
2 files changed, 24 insertions, 1 deletions
diff --git a/networkAddress.cpp b/networkAddress.cpp
index 2d53f75..3db7238 100644
--- a/networkAddress.cpp
+++ b/networkAddress.cpp
@@ -155,3 +155,23 @@ NetworkAddress NetworkAddress::operator&(const NetworkAddress &right) const
}
return false;
}
+
+NetworkAddress NetworkAddress::operator&=(const NetworkAddress &right)
+{
+ if (network_address_type_!=right.network_address_type_)
+ throw std::runtime_error("network_address_types did not match");
+ if (network_address_type_==ipv4)
+ {
+ ipv4_address_.s_addr &= right.ipv4_address_.s_addr;
+ return *this;
+ } else if (network_address_type_==ipv6) {
+ for(int i=0;i<4;i++)
+ ipv6_address_.s6_addr32[i]&=right.ipv6_address_.s6_addr32[i];
+ return *this;
+ } else if (network_address_type_==ethernet) {
+ //TODO
+ } else {
+ //TODO
+ }
+ return false;
+}
diff --git a/networkAddress.h b/networkAddress.h
index f20f018..e4f5064 100644
--- a/networkAddress.h
+++ b/networkAddress.h
@@ -59,14 +59,17 @@ public:
network_address_type_t getNetworkAddressType();
bool operator<(const NetworkAddress &s) const;
NetworkAddress operator&(const NetworkAddress &s) const;
+ NetworkAddress operator&=(const NetworkAddress &s);
NetworkAddress operator<<(uint8_t shift) const;
-private:
+protected:
Mutex mutex_;
in_addr ipv4_address_;
in6_addr ipv6_address_;
uint64_t ethernet_address_;
network_address_type_t network_address_type_;
+private:
+ NetworkAddress operator=(const NetworkAddress &s);
};
#endif