summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-01-21 00:07:07 +0000
committerChristian Pointner <equinox@anytun.org>2009-01-21 00:07:07 +0000
commitfd7e04ea8b40270c4181c6910cf4ca1437c68cad (patch)
treeb78eec0f0a75149a6462bd25e7e8ee29b8b95dce /src
parentsafer handling of registry functions (diff)
tun mode works now on windows
Diffstat (limited to 'src')
-rw-r--r--src/anytun.suobin52736 -> 53760 bytes
-rw-r--r--src/anytun.vcproj2
-rw-r--r--src/deviceConfig.hpp3
-rw-r--r--src/networkAddress.cpp24
-rw-r--r--src/networkAddress.h3
-rw-r--r--src/win32/tunDevice.cpp27
6 files changed, 50 insertions, 9 deletions
diff --git a/src/anytun.suo b/src/anytun.suo
index a2e5d9e..6e9cf16 100644
--- a/src/anytun.suo
+++ b/src/anytun.suo
Binary files differ
diff --git a/src/anytun.vcproj b/src/anytun.vcproj
index b10773f..1f4d47d 100644
--- a/src/anytun.vcproj
+++ b/src/anytun.vcproj
@@ -42,7 +42,7 @@
Name="VCCLCompilerTool"
AdditionalOptions="/I &quot;C:\Program Files\boost\boost_1_35_0\&quot;"
Optimization="0"
- PreprocessorDefinitions="LOG_STDOUT;USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;NO_SYSLOG;NO_SIGNALCONTROLLER;WIN32_LEAN_AND_MEAN"
+ PreprocessorDefinitions="NO_ROUTING;LOG_STDOUT;USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;NO_SYSLOG;NO_SIGNALCONTROLLER;WIN32_LEAN_AND_MEAN"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
diff --git a/src/deviceConfig.hpp b/src/deviceConfig.hpp
index a3dbe74..acca46e 100644
--- a/src/deviceConfig.hpp
+++ b/src/deviceConfig.hpp
@@ -65,6 +65,9 @@ public:
type_ = TYPE_TUN;
else if(dev_type == "tap")
type_ = TYPE_TAP;
+
+ if(type_ == TYPE_TUN && (ifcfg_lp == "" || ifcfg_rnmp == ""))
+ throw std::runtime_error("Device type tun requires ifconfig parameters (--ifconfig)");
#endif
if(ifcfg_lp != "")
diff --git a/src/networkAddress.cpp b/src/networkAddress.cpp
index f922c00..059b670 100644
--- a/src/networkAddress.cpp
+++ b/src/networkAddress.cpp
@@ -105,6 +105,30 @@ network_address_type_t NetworkAddress::getNetworkAddressType() const
return network_address_type_;
}
+const boost::asio::ip::address_v4& NetworkAddress::getNetworkAddressV4() const
+{
+ if(network_address_type_ != ipv4)
+ throw std::runtime_error("wrong address type");
+
+ return ipv4_address_;
+}
+
+const boost::asio::ip::address_v6& NetworkAddress::getNetworkAddressV6() const
+{
+ if(network_address_type_ != ipv6)
+ throw std::runtime_error("wrong address type");
+
+ return ipv6_address_;
+}
+
+const u_int64_t NetworkAddress::getNetworkAdrressEther() const
+{
+ if(network_address_type_ != ethernet)
+ throw std::runtime_error("wrong address type");
+
+ return ethernet_address_;
+}
+
std::string NetworkAddress::toString() const
{
if (network_address_type_==ipv4){
diff --git a/src/networkAddress.h b/src/networkAddress.h
index f866cca..7510eb1 100644
--- a/src/networkAddress.h
+++ b/src/networkAddress.h
@@ -70,6 +70,9 @@ public:
ipv4_bytes_type to_bytes_v4() const;
ipv6_bytes_type to_bytes_v6() const;
ethernet_bytes_type to_bytes_ethernet() const;
+ const boost::asio::ip::address_v4& getNetworkAddressV4() const;
+ const boost::asio::ip::address_v6& getNetworkAddressV6() const;
+ const u_int64_t getNetworkAdrressEther() const;
protected:
Mutex mutex_;
boost::asio::ip::address_v4 ipv4_address_;
diff --git a/src/win32/tunDevice.cpp b/src/win32/tunDevice.cpp
index e4c2cf9..e6167d3 100644
--- a/src/win32/tunDevice.cpp
+++ b/src/win32/tunDevice.cpp
@@ -31,24 +31,23 @@
#include <string.h>
#include <sstream>
+#include <windows.h>
+#include <winioctl.h>
+#include "../endian.h"
#include "../tunDevice.h"
#include "../threadUtils.hpp"
#include "../log.h"
#include "common.h"
-#include <windows.h>
-#include <winioctl.h>
#define REG_KEY_LENGTH 256
#define REG_NAME_LENGTH 256
TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifcfg_lp, std::string ifcfg_rnmp) : conf_(dev_name, dev_type, ifcfg_lp, ifcfg_rnmp, 1400)
{
-// if(conf_.type_ != TYPE_TUN && conf_.type_ != TYPE_TAP)
-// throw std::runtime_error("unable to recognize type of device (tun or tap)");
- if(conf_.type_ != TYPE_TAP)
- throw std::runtime_error("currently only support for typ devices on windows");
+ if(conf_.type_ != TYPE_TUN && conf_.type_ != TYPE_TAP)
+ throw std::runtime_error("unable to recognize type of device (tun or tap)");
HKEY key, key2;
LONG err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_ENUMERATE_SUB_KEYS, &key);
@@ -126,6 +125,18 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
actual_node_ = adapterid;
actual_name_ = adaptername;
+ if(conf_.type_ == TYPE_TUN) {
+ u_long ep[2];
+ ep[0] = htonl(conf_.local_.getNetworkAddressV4().to_ulong());
+ ep[1] = htonl(conf_.remote_netmask_.getNetworkAddressV4().to_ulong());
+ if(!DeviceIoControl(handle_, TAP_IOCTL_CONFIG_POINT_TO_POINT, ep, sizeof(ep), ep, sizeof(ep), &len, NULL)) {
+ CloseHandle(handle_);
+ std::stringstream msg;
+ msg << "Unable to set device point-to-point mode: " << LogErrno(GetLastError());
+ throw std::runtime_error(msg.str());
+ }
+ }
+
int status = true;
if(!DeviceIoControl(handle_, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL)) {
CloseHandle(handle_);
@@ -134,8 +145,8 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
throw std::runtime_error(msg.str());
}
- if(ifcfg_lp != "" && ifcfg_rnmp != "")
- do_ifconfig();
+// if(ifcfg_lp != "" && ifcfg_rnmp != "")
+// do_ifconfig();
roverlapped_.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
woverlapped_.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);