changeset 22:38d495566d1c

Re-added some debugging messages to nacltai protocol code, enabled by the DEBUG environment variable
author Ivo Smits <Ivo@UCIS.nl>
date Sun, 27 Feb 2011 23:52:32 +0100
parents c1e5af9329f1
children bd4259de8459
files src/common.c src/proto.nacltai.c
diffstat 2 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/common.c	Sun Feb 27 22:48:51 2011 +0100
+++ b/src/common.c	Sun Feb 27 23:52:32 2011 +0100
@@ -77,9 +77,11 @@
 	extern int errorexitp(const char*);
 	extern void print_header();
 	extern void hex2bin(unsigned char*, unsigned char*, int);
+	extern int debug;
 #else
 
 char* (*getconf)(const char*) = getenv;
+int debug = 0;
 
 int errorexit(const char* text) {
 	fprintf(stderr, "%s\n", text);
@@ -92,7 +94,7 @@
 
 void print_header() {
 	fprintf(stderr, "UCIS QuickTun (c) 2010 Ivo Smits <Ivo@UCIS.nl>\n");
-	fprintf(stderr, "More information: http://wiki.qontrol.nl/QuickTun\n");
+	fprintf(stderr, "More information: http://wiki.ucis.nl/QuickTun\n");
 }
 
 int init_udp(struct qtsession* session) {
@@ -189,6 +191,7 @@
 }
 
 int qtrun(struct qtproto* p) {
+	if (getconf("DEBUG")) debug = 1;
 	struct qtsession session;
 	session.protocol = *p;
 
--- a/src/proto.nacltai.c	Sun Feb 27 22:48:51 2011 +0100
+++ b/src/proto.nacltai.c	Sun Feb 27 23:52:32 2011 +0100
@@ -118,20 +118,20 @@
 }
 
 static int encode(struct qtsession* sess, char* raw, char* enc, int len) {
-//	fprintf(stderr, "Encoding packet of %d bytes from %d to %d\n", len, raw, enc);
+	if (debug) fprintf(stderr, "Encoding packet of %d bytes from %d to %d\n", len, raw, enc);
 	struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data;
 	memset(raw, 0, crypto_box_ZEROBYTES);
 	taia_now(&d->cdtaic);
 	taia_pack(d->cenonce + nonceoffset, &(d->cdtaic));
-	if (crypto_box_afternm(enc, raw, len + crypto_box_ZEROBYTES, d->cenonce, d->cbefore)) return errorexit("Crypto failed");
+	if (crypto_box_afternm(enc, raw, len + crypto_box_ZEROBYTES, d->cenonce, d->cbefore)) return errorexit("Encryption failed");
 	memcpy((void*)(enc + crypto_box_BOXZEROBYTES - noncelength), d->cenonce + nonceoffset, noncelength);
 	len += overhead;
-//	fprintf(stderr, "Encoded packet of %d bytes from %d to %d\n", len, raw, enc);
+	if (debug) fprintf(stderr, "Encoded packet of %d bytes from %d to %d\n", len, raw, enc);
 	return len;
 }
 
 static int decode(struct qtsession* sess, char* enc, char* raw, int len) {
-//	fprintf(stderr, "Decoding packet of %d bytes from %d to %d\n", len, enc, raw);
+	if (debug) fprintf(stderr, "Decoding packet of %d bytes from %d to %d\n", len, enc, raw);
 	struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data;
 	int i;
 	if (len < overhead) {
@@ -151,7 +151,7 @@
 		return 0;
 	}
 	d->cdtaip = d->cdtaic;
-//	fprintf(stderr, "Decoded packet of %d bytes from %d to %d\n", len, enc, raw);
+	if (debug) fprintf(stderr, "Decoded packet of %d bytes from %d to %d\n", len, enc, raw);
 	return len;
 }