diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-01-24 13:51:31 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-01-24 13:51:31 +0000 |
commit | 17be501e7657aea25b76597940da3cfc76df4970 (patch) | |
tree | 862372a54aa940e8b47f88822fb8f7e8dec59a03 /src/vpn | |
parent | d157355d7e3913dda394e7dcccae03b0e7c129b7 (diff) | |
download | gnunet-17be501e7657aea25b76597940da3cfc76df4970.tar.gz gnunet-17be501e7657aea25b76597940da3cfc76df4970.zip |
added debug logics to print to and read from STDIN, instead of from
named pipes
moved declaration of hdr outside of the ifs
fixed an incorrect comparison introduced in last commit
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-helper-vpn-windows.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c index f9a2f0f9a..690f6fa63 100644 --- a/src/vpn/gnunet-helper-vpn-windows.c +++ b/src/vpn/gnunet-helper-vpn-windows.c | |||
@@ -54,7 +54,7 @@ | |||
54 | * Should we print (interesting|debug) messages that can happen during | 54 | * Should we print (interesting|debug) messages that can happen during |
55 | * normal operation? | 55 | * normal operation? |
56 | */ | 56 | */ |
57 | #define DEBUG GNUNET_NO | 57 | //#define DEBUG GNUNET_YES |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE) | 60 | * Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE) |
@@ -232,7 +232,7 @@ execute_shellcommand (const char *command) | |||
232 | (NULL == (pipe = _popen (command, "rt"))) ) | 232 | (NULL == (pipe = _popen (command, "rt"))) ) |
233 | return EINVAL; | 233 | return EINVAL; |
234 | 234 | ||
235 | #ifdef TESTING | 235 | #ifdef DEBUG |
236 | fprintf (stderr, "DEBUG: Command output: \n"); | 236 | fprintf (stderr, "DEBUG: Command output: \n"); |
237 | char output[LINE_LEN]; | 237 | char output[LINE_LEN]; |
238 | while (NULL != fgets (output, sizeof (output), pipe)) | 238 | while (NULL != fgets (output, sizeof (output), pipe)) |
@@ -996,6 +996,7 @@ static BOOL | |||
996 | attempt_read_stdin (struct io_facility * input_facility, | 996 | attempt_read_stdin (struct io_facility * input_facility, |
997 | struct io_facility * output_facility) | 997 | struct io_facility * output_facility) |
998 | { | 998 | { |
999 | struct GNUNET_MessageHeader * hdr; | ||
999 | BOOL status; | 1000 | BOOL status; |
1000 | switch (input_facility->facility_state) | 1001 | switch (input_facility->facility_state) |
1001 | { | 1002 | { |
@@ -1013,7 +1014,7 @@ attempt_read_stdin (struct io_facility * input_facility, | |||
1013 | /* Check how the task is handled */ | 1014 | /* Check how the task is handled */ |
1014 | if (status && (sizeof (struct GNUNET_MessageHeader) < input_facility->buffer_size)) | 1015 | if (status && (sizeof (struct GNUNET_MessageHeader) < input_facility->buffer_size)) |
1015 | {/* async event processed immediately*/ | 1016 | {/* async event processed immediately*/ |
1016 | struct GNUNET_MessageHeader * hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; | 1017 | hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; |
1017 | 1018 | ||
1018 | /* reset event manually*/ | 1019 | /* reset event manually*/ |
1019 | if (!SetEvent (input_facility->overlapped.hEvent)) | 1020 | if (!SetEvent (input_facility->overlapped.hEvent)) |
@@ -1086,7 +1087,7 @@ attempt_read_stdin (struct io_facility * input_facility, | |||
1086 | FALSE); | 1087 | FALSE); |
1087 | if (status) | 1088 | if (status) |
1088 | {/* successful return for a queued operation */ | 1089 | {/* successful return for a queued operation */ |
1089 | struct GNUNET_MessageHeader * hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; | 1090 | hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; |
1090 | 1091 | ||
1091 | if (!ResetEvent (input_facility->overlapped.hEvent)) | 1092 | if (!ResetEvent (input_facility->overlapped.hEvent)) |
1092 | return FALSE; | 1093 | return FALSE; |
@@ -1318,6 +1319,12 @@ run (HANDLE tap_handle) | |||
1318 | tap_read.handle = tap_handle; | 1319 | tap_read.handle = tap_handle; |
1319 | tap_write.handle = tap_handle; | 1320 | tap_write.handle = tap_handle; |
1320 | 1321 | ||
1322 | #ifdef DEBUG_TO_CONSOLE | ||
1323 | /* Debug output to console STDIN/STDOUT*/ | ||
1324 | std_in.handle = parent_std_in_handle; | ||
1325 | std_out.handle = parent_std_out_handle; | ||
1326 | #else | ||
1327 | |||
1321 | /* | 1328 | /* |
1322 | * Find out the types of our handles. | 1329 | * Find out the types of our handles. |
1323 | * This part is a problem, because in windows we need to handle files, | 1330 | * This part is a problem, because in windows we need to handle files, |
@@ -1351,15 +1358,16 @@ run (HANDLE tap_handle) | |||
1351 | fprintf (stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe!\n"); | 1358 | fprintf (stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe!\n"); |
1352 | goto teardown; | 1359 | goto teardown; |
1353 | } | 1360 | } |
1354 | 1361 | #endif | |
1355 | while (std_out.path_open || tap_write.path_open) | 1362 | |
1363 | while (std_out.path_open && tap_write.path_open) | ||
1356 | { | 1364 | { |
1357 | /* perform READ from stdin if possible */ | 1365 | /* perform READ from stdin if possible */ |
1358 | if (std_in.path_open && tap_write.path_open && (!attempt_read_stdin (&std_in, &tap_write))) | 1366 | if (std_in.path_open && (!attempt_read_stdin (&std_in, &tap_write))) |
1359 | break; | 1367 | break; |
1360 | 1368 | ||
1361 | /* perform READ from tap if possible */ | 1369 | /* perform READ from tap if possible */ |
1362 | if (tap_read.path_open && std_out.path_open && (!attempt_read_tap (&tap_read, &std_out))) | 1370 | if (tap_read.path_open && (!attempt_read_tap (&tap_read, &std_out))) |
1363 | break; | 1371 | break; |
1364 | 1372 | ||
1365 | /* perform WRITE to tap if possible */ | 1373 | /* perform WRITE to tap if possible */ |
@@ -1388,7 +1396,7 @@ teardown_final: | |||
1388 | * | 1396 | * |
1389 | * @param argc must be 6 | 1397 | * @param argc must be 6 |
1390 | * @param argv 0: binary name (gnunet-helper-vpn) | 1398 | * @param argv 0: binary name (gnunet-helper-vpn) |
1391 | * 1: tunnel interface name (gnunet-vpn) | 1399 | * 1: tunnel interface prefix (gnunet-vpn) |
1392 | * 2: IPv6 address (::1), "-" to disable | 1400 | * 2: IPv6 address (::1), "-" to disable |
1393 | * 3: IPv6 netmask length in bits (64), ignored if #2 is "-" | 1401 | * 3: IPv6 netmask length in bits (64), ignored if #2 is "-" |
1394 | * 4: IPv4 address (1.2.3.4), "-" to disable | 1402 | * 4: IPv4 address (1.2.3.4), "-" to disable |
@@ -1405,7 +1413,7 @@ main (int argc, char **argv) | |||
1405 | 1413 | ||
1406 | if (6 != argc) | 1414 | if (6 != argc) |
1407 | { | 1415 | { |
1408 | fprintf (stderr, "FATAL: must supply 5 arguments!\n"); | 1416 | fprintf (stderr, "FATAL: must supply 5 arguments!\nUsage:\ngnunet-helper-vpn <if name prefix> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n", argv[0]); |
1409 | return 1; | 1417 | return 1; |
1410 | } | 1418 | } |
1411 | 1419 | ||