summaryrefslogtreecommitdiff
path: root/src/win32/tunDevice.cpp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-01-19 23:21:30 +0000
committerChristian Pointner <equinox@anytun.org>2009-01-19 23:21:30 +0000
commitcf44e028d076399177619d8bc523fa13521e0b5e (patch)
treefdf5577e32b1ad656f32101e530fe255b3089ee6 /src/win32/tunDevice.cpp
parentfixed overlapped handling of read and write at windows tundevice (diff)
fixed silly bug at new tundevice
Diffstat (limited to 'src/win32/tunDevice.cpp')
-rw-r--r--src/win32/tunDevice.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/win32/tunDevice.cpp b/src/win32/tunDevice.cpp
index af9b194..559d520 100644
--- a/src/win32/tunDevice.cpp
+++ b/src/win32/tunDevice.cpp
@@ -88,9 +88,6 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
std::stringstream tapname;
tapname << USERMODEDEVICEDIR << adapterid << TAPSUFFIX;
-
- cLog.msg(Log::PRIO_DEBUG) << "'" << tapname.str() << "'";
-
handle_ = CreateFile(tapname.str().c_str(), GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
if(handle_ == INVALID_HANDLE_VALUE) {
std::stringstream msg;
@@ -98,6 +95,9 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
throw std::runtime_error(msg.str());
}
+ conf_.type_ = TYPE_TAP;
+ actual_name_ = adapterid;
+
int status = true;
if(!DeviceIoControl(handle_, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL)) {
std::stringstream msg;
@@ -105,8 +105,6 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
throw std::runtime_error(msg.str());
}
- conf_.type_ = TYPE_TAP;
-
if(ifcfg_lp != "" && ifcfg_rnmp != "")
do_ifconfig();
}
@@ -140,17 +138,17 @@ int TunDevice::read(u_int8_t* buf, u_int32_t len)
return -1;
}
}
- else
+ else {
cLog.msg(Log::PRIO_ERR) << "Error while reading from device: " << LogErrno(GetLastError());
-
- return -1;
+ return -1;
+ }
}
return lenout;
}
int TunDevice::write(u_int8_t* buf, u_int32_t len)
{
- DWORD lenout;
+ DWORD lenout;
OVERLAPPED overlapped;
overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
overlapped.Offset = 0;
@@ -166,12 +164,12 @@ int TunDevice::write(u_int8_t* buf, u_int32_t len)
return -1;
}
}
- else
+ else {
cLog.msg(Log::PRIO_ERR) << "Error while writing to device: " << LogErrno(GetLastError());
-
- return -1;
+ return -1;
+ }
}
- return lenout;
+ return lenout;
}
void TunDevice::init_post()