diff options
author | Christian Pointner <equinox@anytun.org> | 2008-02-27 22:50:01 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2008-02-27 22:50:01 +0000 |
commit | 5f8123d7e45d925739a84eb208da2eb8edcd4179 (patch) | |
tree | 3bf0f272edc59ad9d68d089eebf5c2cf9ce0c88b | |
parent | added route syncing (diff) |
added get Src/Dst Address @ plainPacket
-rw-r--r-- | anytun.cpp | 3 | ||||
-rw-r--r-- | plainPacket.cpp | 60 | ||||
-rw-r--r-- | plainPacket.h | 8 |
3 files changed, 67 insertions, 4 deletions
@@ -66,9 +66,6 @@ #include "threadParam.h" -#define PAYLOAD_TYPE_TAP 0x6558 -#define PAYLOAD_TYPE_TUN 0x0800 - #define MAX_PACKET_LENGTH 1600 #define SESSION_KEYLEN_AUTH 20 // TODO: hardcoded size 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(); +} diff --git a/plainPacket.h b/plainPacket.h index e44df32..03ae507 100644 --- a/plainPacket.h +++ b/plainPacket.h @@ -34,12 +34,18 @@ #include "datatypes.h" #include "buffer.h" +#include "networkAddress.h" + class Cipher; /** * plain SATP packet class<br> * includes payload_type and payload */ +#define PAYLOAD_TYPE_TAP 0x6558 +#define PAYLOAD_TYPE_TUN 0x0800 +#define PAYLOAD_TYPE_TUN6 0x86DD + class PlainPacket : public Buffer { public: @@ -85,6 +91,8 @@ public: */ u_int8_t* getPayload(); + NetworkAddress getSrcAddr() const; + NetworkAddress getDstAddr() const; private: PlainPacket(); |