summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networkAddress.cpp28
-rw-r--r--networkAddress.h8
2 files changed, 34 insertions, 2 deletions
diff --git a/networkAddress.cpp b/networkAddress.cpp
index b6e4528..ca132db 100644
--- a/networkAddress.cpp
+++ b/networkAddress.cpp
@@ -33,7 +33,7 @@
#include "networkAddress.h"
-NetworkAddress::NetworkAddress():address_length_(0)
+NetworkAddress::NetworkAddress()
{
}
@@ -43,6 +43,17 @@ NetworkAddress::~NetworkAddress()
void NetworkAddress::setNetworkAddress(const network_address_type_t type, const char * address )
{
+ if (type==ipv4)
+ {
+ inet_pton(AF_INET, address, &ipv4_address_);
+ } else if (type==ipv6) {
+ inet_pton(AF_INET6, address, &ipv6_address_);
+ } else if (type==ethernet) {
+ //TODO
+ } else {
+ //TODO
+ }
+ network_address_type_ = type;
}
void NetworkAddress::getNetworkAddress(const char *)
@@ -55,5 +66,20 @@ network_address_type_t NetworkAddress::getNetworkAddressType()
bool NetworkAddress::operator<(const NetworkAddress &right) const
{
+ if (network_address_type_!=right.network_address_type_)
+ return false;
+ if (network_address_type_==ipv4)
+ {
+ return (ipv4_address_.s_addr < right.ipv4_address_.s_addr);
+ } else if (network_address_type_==ipv6) {
+ for(int i=0;i++;i<4)
+ if (ipv6_address_.s6_addr32[i]<right.ipv6_address_.s6_addr32[i])
+ return true;
+ return false;
+ } else if (network_address_type_==ethernet) {
+ //TODO
+ } else {
+ //TODO
+ }
}
diff --git a/networkAddress.h b/networkAddress.h
index 59430e5..cbb483d 100644
--- a/networkAddress.h
+++ b/networkAddress.h
@@ -34,6 +34,10 @@
#include "threadUtils.hpp"
#include "datatypes.h"
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
enum network_address_type_t
{
ipv4,
@@ -53,7 +57,9 @@ public:
private:
bool operator<(const NetworkAddress &s) const;
Mutex mutex_;
- uint8_t address_length_;
+ in_addr ipv4_address_;
+ in6_addr ipv6_address_;
+ uint64_t ethernet_address_;
network_address_type_t network_address_type_;
};