summaryrefslogtreecommitdiff
path: root/plainPacket.cpp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-02-27 22:50:01 +0000
committerChristian Pointner <equinox@anytun.org>2008-02-27 22:50:01 +0000
commit5f8123d7e45d925739a84eb208da2eb8edcd4179 (patch)
tree3bf0f272edc59ad9d68d089eebf5c2cf9ce0c88b /plainPacket.cpp
parentadded route syncing (diff)
added get Src/Dst Address @ plainPacket
Diffstat (limited to 'plainPacket.cpp')
-rw-r--r--plainPacket.cpp60
1 files changed, 59 insertions, 1 deletions
diff --git a/plainPacket.cpp b/plainPacket.cpp
index 37c4338..1789854 100644
--- a/plainPacket.cpp
+++ b/plainPacket.cpp
@@ -31,11 +31,13 @@
#include <stdexcept>
#include <iostream>
#include <arpa/inet.h>
+#include <net/ethernet.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
#include "datatypes.h"
#include "plainPacket.h"
-
PlainPacket::PlainPacket(u_int32_t payload_length, bool allow_realloc) : Buffer(payload_length + sizeof(payload_type_t), allow_realloc)
{
payload_type_ = reinterpret_cast<payload_type_t*>(buf_);
@@ -80,3 +82,59 @@ u_int8_t* PlainPacket::getPayload()
{
return payload_;
}
+
+
+NetworkAddress PlainPacket::getSrcAddr() const
+{
+ if(!payload_type_ || !payload_)
+ return NetworkAddress();
+
+ if(PAYLOAD_TYPE_TAP) // Ehternet
+ {
+ // TODO
+ return NetworkAddress();
+ }
+ else if(PAYLOAD_TYPE_TUN) // IPv4
+ {
+ if(length_ < (sizeof(payload_type_t)+sizeof(struct ip)))
+ return NetworkAddress();
+ struct ip* hdr = reinterpret_cast<struct ip*>(payload_);
+ return NetworkAddress(hdr->ip_src);
+ }
+ else if(PAYLOAD_TYPE_TUN6) // IPv6
+ {
+ if(length_ < (sizeof(payload_type_t)+sizeof(struct ip6_hdr)))
+ return NetworkAddress();
+ struct ip6_hdr* hdr = reinterpret_cast<struct ip6_hdr*>(payload_);
+ return NetworkAddress(hdr->ip6_dst);
+ }
+ return NetworkAddress();
+}
+
+
+NetworkAddress PlainPacket::getDstAddr() const
+{
+ if(!payload_type_ || !payload_)
+ return NetworkAddress();
+
+ if(PAYLOAD_TYPE_TAP) // Ehternet
+ {
+ // TODO
+ return NetworkAddress();
+ }
+ else if(PAYLOAD_TYPE_TUN) // IPv4
+ {
+ if(length_ < (sizeof(payload_type_t)+sizeof(struct ip)))
+ return NetworkAddress();
+ struct ip* hdr = reinterpret_cast<struct ip*>(payload_);
+ return NetworkAddress(hdr->ip_dst);
+ }
+ else if(PAYLOAD_TYPE_TUN6) // IPv6
+ {
+ if(length_ < (sizeof(payload_type_t)+sizeof(struct ip6_hdr)))
+ return NetworkAddress();
+ struct ip6_hdr* hdr = reinterpret_cast<struct ip6_hdr*>(payload_);
+ return NetworkAddress(hdr->ip6_dst);
+ }
+ return NetworkAddress();
+}