summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-01-16 15:49:42 +0000
committerChristian Pointner <equinox@anytun.org>2009-01-16 15:49:42 +0000
commit88a0ecb3917a38ef5edf95f302b9aed1b71ef36d (patch)
treef1b46011a80d594349c2fbc5ef1d3563cdaa74c8 /src
parentsmall cleanup (diff)
added Log to stdout
added dummy stdio tun device some cleanups (windows)
Diffstat (limited to 'src')
-rw-r--r--src/anytun.cpp10
-rw-r--r--src/anytun.suobin35840 -> 39936 bytes
-rw-r--r--src/anytun.vcproj2
-rw-r--r--src/buffer.cpp2
-rw-r--r--src/datatypes.h2
-rw-r--r--src/log.cpp20
-rw-r--r--src/log.h18
-rw-r--r--src/options.cpp2
-rw-r--r--src/packetSource.cpp2
-rw-r--r--src/win32/tunDevice.cpp8
10 files changed, 49 insertions, 17 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp
index eb7c1a8..8c7c239 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -396,7 +396,7 @@ int main(int argc, char* argv[])
for(rit = routes.begin(); rit != routes.end(); ++rit)
{
NetworkAddress addr( rit->net_addr );
- NetworkPrefix prefix( addr, rit->prefix_length );
+ NetworkPrefix prefix( addr, static_cast<u_int8_t>(rit->prefix_length));
gRoutingTable.addRoute( prefix, gOpt.getMux() );
}
if (connect_to.begin() == connect_to.end() && routes.begin() == routes.end() && gOpt.getDevType()=="tun")
@@ -485,14 +485,18 @@ int main(int argc, char* argv[])
catch(std::runtime_error& e)
{
cLog.msg(Log::PRIO_ERR) << "uncaught runtime error, exiting: " << e.what();
- if(!daemonized)
+#ifndef LOGSTDOUT
+ if(!daemonized)
std::cout << "uncaught runtime error, exiting: " << e.what() << std::endl;
+#endif
}
catch(std::exception& e)
{
cLog.msg(Log::PRIO_ERR) << "uncaught exception, exiting: " << e.what();
- if(!daemonized)
+#ifndef LOGSTDOUT
+ if(!daemonized)
std::cout << "uncaught exception, exiting: " << e.what() << std::endl;
+#endif
}
}
diff --git a/src/anytun.suo b/src/anytun.suo
index 0099b24..90b43cf 100644
--- a/src/anytun.suo
+++ b/src/anytun.suo
Binary files differ
diff --git a/src/anytun.vcproj b/src/anytun.vcproj
index 3e5b97c..bc74de4 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="NOCRYPT;NODAEMON;NOEXEC;NOPACKED;NOSYSLOG;NOSIGNALCONTROLLER;WIN32_LEAN_AND_MEAN"
+ PreprocessorDefinitions="LOGSTDOUT;NOCRYPT;NODAEMON;NOEXEC;NOPACKED;NOSYSLOG;NOSIGNALCONTROLLER;WIN32_LEAN_AND_MEAN"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
diff --git a/src/buffer.cpp b/src/buffer.cpp
index 8e7bf98..2597845 100644
--- a/src/buffer.cpp
+++ b/src/buffer.cpp
@@ -73,7 +73,7 @@ Buffer::Buffer(u_int8_t* data, u_int32_t length, bool allow_realloc) : length_(l
std::memcpy(buf_, data, length_);
}
-Buffer::Buffer(std::string hex_data, bool allow_realloc) : length_(hex_data.size()/2),
+Buffer::Buffer(std::string hex_data, bool allow_realloc) : length_(static_cast<u_int32_t>(hex_data.size())/2),
real_length_(length_ + Buffer::OVER_SIZE_),
allow_realloc_(allow_realloc)
{
diff --git a/src/datatypes.h b/src/datatypes.h
index 8a7daff..2fe492c 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -47,7 +47,7 @@ typedef boost::int64_t int64_t;
typedef u_int32_t window_size_t;
typedef u_int32_t seq_nr_t;
-#define SEQ_NR_MAX boost::integer_traits<seq_nr_t>::max()
+#define SEQ_NR_MAX 0xFFFFFFFF
typedef u_int16_t sender_id_t;
typedef u_int16_t payload_type_t;
typedef u_int16_t mux_t;
diff --git a/src/log.cpp b/src/log.cpp
index 65496d3..072f8c1 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -74,6 +74,9 @@ LogStringBuilder::~LogStringBuilder()
#ifndef NOSYSLOG
syslog(prio | log.getFacility(), "%s", stream.str().c_str());
#endif
+#ifdef LOGSTDOUT
+ std::cout << "LOG-" << Log::prioToString(prio) << ": " << stream.str() << std::endl;
+#endif
}
Log& Log::instance()
@@ -100,6 +103,23 @@ Log::~Log()
#endif
}
+#ifdef NOSYSLOG
+std::string Log::prioToString(int prio)
+{
+ switch(prio) {
+ case PRIO_EMERG: return "EMERG";
+ case PRIO_ALERT: return "ALERT";
+ case PRIO_CRIT: return "CRIT";
+ case PRIO_ERR: return "ERR";
+ case PRIO_WARNING: return "WARNING";
+ case PRIO_NOTICE: return "NOTICE";
+ case PRIO_INFO: return "INFO";
+ case PRIO_DEBUG: return "DEBUG";
+ default: return "UNKNOWN";
+ }
+}
+#endif
+
void Log::open()
{
#ifndef NOSYSLOG
diff --git a/src/log.h b/src/log.h
index e1f9163..29f3cb8 100644
--- a/src/log.h
+++ b/src/log.h
@@ -136,14 +136,16 @@ public:
static const int FAC_LOCAL6 = 0;
static const int FAC_LOCAL7 = 0;
- static const int PRIO_EMERG = 0;
- static const int PRIO_ALERT = 0;
- static const int PRIO_CRIT = 0;
- static const int PRIO_ERR = 0;
- static const int PRIO_WARNING = 0;
- static const int PRIO_NOTICE = 0;
- static const int PRIO_INFO = 0;
- static const int PRIO_DEBUG = 0;
+ static const int PRIO_EMERG = 1;
+ static const int PRIO_ALERT = 2;
+ static const int PRIO_CRIT = 3;
+ static const int PRIO_ERR = 4;
+ static const int PRIO_WARNING = 5;
+ static const int PRIO_NOTICE = 6;
+ static const int PRIO_INFO = 7;
+ static const int PRIO_DEBUG = 8;
+
+ static std::string prioToString(int prio);
#endif
static Log& instance();
diff --git a/src/options.cpp b/src/options.cpp
index 40737af..4700047 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -209,7 +209,7 @@ int32_t Options::parse(int argc, char* argv[])
return i;
}
- ld_kdr_ = ld_kdr_tmp;
+ ld_kdr_ = static_cast<int8_t>(ld_kdr_tmp);
if(cipher_ == "null" && auth_algo_ == "null")
kd_prf_ = "null";
diff --git a/src/packetSource.cpp b/src/packetSource.cpp
index 9a35cc3..b6eebbe 100644
--- a/src/packetSource.cpp
+++ b/src/packetSource.cpp
@@ -54,7 +54,7 @@ UDPPacketSource::UDPPacketSource(std::string localaddr, std::string port) : sock
u_int32_t UDPPacketSource::recv(u_int8_t* buf, u_int32_t len, PacketSourceEndpoint& remote)
{
- return sock_.receive_from(boost::asio::buffer(buf, len), remote);
+ return static_cast<u_int32_t>(sock_.receive_from(boost::asio::buffer(buf, len), remote));
}
void UDPPacketSource::send(u_int8_t* buf, u_int32_t len, PacketSourceEndpoint remote)
diff --git a/src/win32/tunDevice.cpp b/src/win32/tunDevice.cpp
index 5bc453d..c162ac3 100644
--- a/src/win32/tunDevice.cpp
+++ b/src/win32/tunDevice.cpp
@@ -56,11 +56,17 @@ int TunDevice::fix_return(int ret, size_t pi_length)
int TunDevice::read(u_int8_t* buf, u_int32_t len)
{
- return 0;
+ 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;
}
int TunDevice::write(u_int8_t* buf, u_int32_t len)
{
+ std::cout << Buffer(buf, len).getHexDumpOneLine() << std::endl;
return 0;
}