summaryrefslogtreecommitdiff
path: root/src/anytun.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/anytun.cpp
parentfixed overlapped handling of read and write at windows tundevice (diff)
fixed silly bug at new tundevice
Diffstat (limited to 'src/anytun.cpp')
-rw-r--r--src/anytun.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp
index 1886a60..3a1ab73 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -168,7 +168,12 @@ void sender(void* p)
encrypted_packet.setLength(MAX_PACKET_LENGTH);
// read packet from device
- u_int32_t len = param->dev.read(plain_packet.getPayload(), plain_packet.getPayloadLength());
+ int len = param->dev.read(plain_packet.getPayload(), plain_packet.getPayloadLength());
+ if(len < 0)
+ continue; // silently ignore device read errors, this is probably no good idea...
+
+ if(static_cast<u_int32_t>(len) < PlainPacket::getHeaderLength())
+ continue; // ignore short packets
plain_packet.setPayloadLength(len);
// set payload type
if(param->dev.getType() == TYPE_TUN)
@@ -257,8 +262,11 @@ void receiver(void* p)
encrypted_packet.setLength(MAX_PACKET_LENGTH);
// read packet from socket
- u_int32_t len = param->src.recv(encrypted_packet.getBuf(), encrypted_packet.getLength(), remote_end);
- if(len < EncryptedPacket::getHeaderLength())
+ int len = param->src.recv(encrypted_packet.getBuf(), encrypted_packet.getLength(), remote_end);
+ if(len < 0)
+ continue; // silently ignore socket recv errors, this is probably no good idea...
+
+ if(static_cast<u_int32_t>(len) < EncryptedPacket::getHeaderLength())
continue; // ignore short packets
encrypted_packet.setLength(len);
@@ -319,7 +327,7 @@ void receiver(void* p)
}
catch(std::runtime_error& e)
{
- cLog.msg(Log::PRIO_ERR) << "sender thread died due to an uncaught runtime_error: " << e.what();
+ cLog.msg(Log::PRIO_ERR) << "receiver thread died due to an uncaught runtime_error: " << e.what();
}
catch(std::exception& e)
{