summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networkAddress.cpp20
-rw-r--r--networkAddress.h2
-rw-r--r--options.cpp5
-rw-r--r--plainPacket.cpp16
4 files changed, 36 insertions, 7 deletions
diff --git a/networkAddress.cpp b/networkAddress.cpp
index d87f5ba..8be45e2 100644
--- a/networkAddress.cpp
+++ b/networkAddress.cpp
@@ -91,6 +91,26 @@ network_address_type_t NetworkAddress::getNetworkAddressType()
return network_address_type_;
}
+std::string NetworkAddress::toString() const
+{
+ if (network_address_type_==ipv4){
+ char buf[INET_ADDRSTRLEN];
+ if(!inet_ntop(AF_INET, &ipv4_address_, buf, sizeof(buf)))
+ return std::string("");
+ return std::string(buf);
+ }
+ else if (network_address_type_==ipv6) {
+ char buf[INET6_ADDRSTRLEN];
+ if(!inet_ntop(AF_INET6, &ipv6_address_, buf, sizeof(buf)))
+ return std::string("");
+ return std::string(buf);
+ }
+ else if (network_address_type_==ethernet) {
+ // TODO
+ }
+ return std::string("");
+}
+
bool NetworkAddress::operator<(const NetworkAddress &right) const
{
if (network_address_type_!=right.network_address_type_)
diff --git a/networkAddress.h b/networkAddress.h
index e4f5064..1192fb3 100644
--- a/networkAddress.h
+++ b/networkAddress.h
@@ -37,6 +37,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <string>
enum network_address_type_t
{
@@ -57,6 +58,7 @@ public:
void setNetworkAddress(const network_address_type_t type, const char * address );
void getNetworkAddress(const char *);
network_address_type_t getNetworkAddressType();
+ std::string toString() const;
bool operator<(const NetworkAddress &s) const;
NetworkAddress operator&(const NetworkAddress &s) const;
NetworkAddress operator&=(const NetworkAddress &s);
diff --git a/options.cpp b/options.cpp
index 7e5cac6..2a2b144 100644
--- a/options.cpp
+++ b/options.cpp
@@ -176,6 +176,9 @@ bool Options::parse(int argc, char* argv[])
if(cipher_ == "null")
kd_prf_ = "null";
+ if(cipher_ != "null" && kd_prf_ == "null")
+ kd_prf_ = "aes-ctr";
+
while(!host_port_queue.empty())
{
std::stringstream tmp_stream(host_port_queue.front());
@@ -237,7 +240,7 @@ void Options::printOptions()
std::cout << "cipher='" << cipher_ << "'" << std::endl;
std::cout << "key=" << key_.getHexDumpOneLine() << std::endl;
std::cout << "salt=" << salt_.getHexDumpOneLine() << std::endl;
- std::cout << "kd-prf='" << kd_prf_ << "'" << std::endl;
+ std::cout << "kd_prf='" << kd_prf_ << "'" << std::endl;
std::cout << "auth_algo='" << auth_algo_ << "'" << std::endl;
}
diff --git a/plainPacket.cpp b/plainPacket.cpp
index 1789854..f9c43ae 100644
--- a/plainPacket.cpp
+++ b/plainPacket.cpp
@@ -89,19 +89,21 @@ NetworkAddress PlainPacket::getSrcAddr() const
if(!payload_type_ || !payload_)
return NetworkAddress();
- if(PAYLOAD_TYPE_TAP) // Ehternet
+ payload_type_t type = PAYLOAD_TYPE_T_NTOH(*payload_type_);
+
+ if(type == PAYLOAD_TYPE_TAP) // Ehternet
{
// TODO
return NetworkAddress();
}
- else if(PAYLOAD_TYPE_TUN) // IPv4
+ else if(type == 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
+ else if(type == PAYLOAD_TYPE_TUN6) // IPv6
{
if(length_ < (sizeof(payload_type_t)+sizeof(struct ip6_hdr)))
return NetworkAddress();
@@ -117,19 +119,21 @@ NetworkAddress PlainPacket::getDstAddr() const
if(!payload_type_ || !payload_)
return NetworkAddress();
- if(PAYLOAD_TYPE_TAP) // Ehternet
+ payload_type_t type = PAYLOAD_TYPE_T_NTOH(*payload_type_);
+
+ if(type == PAYLOAD_TYPE_TAP) // Ehternet
{
// TODO
return NetworkAddress();
}
- else if(PAYLOAD_TYPE_TUN) // IPv4
+ else if(type == 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
+ else if(type == PAYLOAD_TYPE_TUN6) // IPv6
{
if(length_ < (sizeof(payload_type_t)+sizeof(struct ip6_hdr)))
return NetworkAddress();