summaryrefslogtreecommitdiff
path: root/src/win32
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-01-19 22:06:52 +0000
committerChristian Pointner <equinox@anytun.org>2009-01-19 22:06:52 +0000
commitc06031014042f10811d43b4daae7d483dbc48bc3 (patch)
treef272ec616c9e6ac3ec8404f622bbb3a286c8d2f0 /src/win32
parentwindows tap device open works now (some cleanup needed) (diff)
first working version of windows TunDevice (currently only tap)
Diffstat (limited to 'src/win32')
-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()