summaryrefslogtreecommitdiff
path: root/src/win32/tunDevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/win32/tunDevice.cpp')
-rw-r--r--src/win32/tunDevice.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/win32/tunDevice.cpp b/src/win32/tunDevice.cpp
index 7fc774e..3049c24 100644
--- a/src/win32/tunDevice.cpp
+++ b/src/win32/tunDevice.cpp
@@ -101,10 +101,12 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
int status = true;
if(!DeviceIoControl(handle_, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL)) {
std::stringstream msg;
- msg << "Unable set device media status: " << LogErrno(GetLastError());
+ msg << "Unable to set device media status: " << LogErrno(GetLastError());
throw std::runtime_error(msg.str());
}
+ conf_.type_ = TYPE_TAP;
+
if(ifcfg_lp != "" && ifcfg_rnmp != "")
do_ifconfig();
}
@@ -122,18 +124,40 @@ int TunDevice::fix_return(int ret, size_t pi_length)
int TunDevice::read(u_int8_t* buf, u_int32_t len)
{
- std::string input;
- std::cin >> input;
- Buffer b(input);
- u_int32_t cpylen = b.getLength() < len ? b.getLength() : len;
- std::memcpy(buf, b.getBuf(), b.getLength());
- return cpylen;
+ DWORD lenout;
+ OVERLAPPED overlapped;
+ overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ overlapped.Offset = 0;
+ overlapped.OffsetHigh = 0;
+// ResetEvent(overlapped.hEvent);
+
+ if(!ReadFile(handle_, buf, len, &lenout, &overlapped)) {
+ DWORD err = GetLastError();
+ if(err == ERROR_IO_PENDING) {
+ WaitForSingleObject(overlapped.hEvent, INFINITE);
+ if(!GetOverlappedResult(handle_, &overlapped, &lenout, FALSE))
+ cLog.msg(Log::PRIO_ERR) << "Error while trying to get overlapped result: " << LogErrno(GetLastError());
+
+ return lenout;
+ }
+ else
+ cLog.msg(Log::PRIO_ERR) << "Error while reading from: " << LogErrno(GetLastError());
+
+ return -1;
+ }
+ return lenout;
}
int TunDevice::write(u_int8_t* buf, u_int32_t len)
{
- std::cout << Buffer(buf, len).getHexDumpOneLine() << std::endl;
- return 0;
+ DWORD lenout;
+ OVERLAPPED overlapped = {0};
+
+ if(!WriteFile(handle_, buf, len, &lenout, &overlapped)) {
+ cLog.msg(Log::PRIO_ERR) << "Error while writing to device: " << LogErrno(GetLastError());
+ return -1;
+ }
+ return lenout;
}
void TunDevice::init_post()