aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport-wlan-helper.c
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2010-12-22 15:24:15 +0000
committerDavid Brodski <david@brodski.eu>2010-12-22 15:24:15 +0000
commit08f8355f7465824373f6c3150b0a750f1a27758b (patch)
tree82e8041da418143847a68e57264b92006ce4d96c /src/transport/gnunet-transport-wlan-helper.c
parent78c035a8492a5d57e0b16d6b784adbca2e817a96 (diff)
downloadgnunet-08f8355f7465824373f6c3150b0a750f1a27758b.tar.gz
gnunet-08f8355f7465824373f6c3150b0a750f1a27758b.zip
Errors fixed
Diffstat (limited to 'src/transport/gnunet-transport-wlan-helper.c')
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 4332e9a0d..48b628e94 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -392,10 +392,11 @@ int ieee80211_radiotap_iterator_next(
392 return -ENOENT; 392 return -ENOENT;
393} 393}
394 394
395#define FIFO_FILE1 "MYFIFOin" 395#define FIFO_FILE1 "/tmp/MYFIFOin"
396#define FIFO_FILE2 "MYFIFOout" 396#define FIFO_FILE2 "/tmp/MYFIFOout"
397#define MAXLINE 5000 397#define MAXLINE 5000
398 398
399int first;
399int closeprog = 0; 400int closeprog = 0;
400 401
401void sigfunc(int sig) 402void sigfunc(int sig)
@@ -404,9 +405,14 @@ void sigfunc(int sig)
404 if(sig != SIGINT || sig != SIGTERM || sig != SIGKILL) 405 if(sig != SIGINT || sig != SIGTERM || sig != SIGKILL)
405 return; 406 return;
406 else 407 else
407 { 408 {
408 closeprog = 1; 409 closeprog = 1;
409 } 410 if (first == 1)
411 {
412 unlink(FIFO_FILE1);
413 unlink(FIFO_FILE2);
414 }
415 }
410} 416}
411 417
412 418
@@ -416,19 +422,18 @@ testmode(int argc, char *argv[])
416{ 422{
417 struct stat st; 423 struct stat st;
418 int erg; 424 int erg;
419 int first; 425
426 int fd[2];
420 FILE *fpin; 427 FILE *fpin;
421 FILE *fpout; 428 FILE *fpout;
422 pid_t pid; 429 pid_t pid;
423 430
424 signal(SIGINT,sigfunc); 431
425 signal(SIGTERM,sigfunc);
426 signal(SIGKILL,sigfunc);
427 432
428 //make the fifos if needed 433 //make the fifos if needed
429 if (stat(FIFO_FILE1, &st) != 0) 434 if (stat(FIFO_FILE1, &st) != 0)
430 { 435 {
431 if (stat(FIFO_FILE2, &st) != 0) 436 if (stat(FIFO_FILE2, &st) == 0)
432 { 437 {
433 perror("FIFO 2 exists, but FIFO 1 not"); 438 perror("FIFO 2 exists, but FIFO 1 not");
434 exit(1); 439 exit(1);
@@ -452,7 +457,7 @@ testmode(int argc, char *argv[])
452 else 457 else
453 { 458 {
454 first = 0; 459 first = 0;
455 if (stat(FIFO_FILE2, &st) == 0) 460 if (stat(FIFO_FILE2, &st) != 0)
456 { 461 {
457 perror("FIFO 1 exists, but FIFO 2 not"); 462 perror("FIFO 1 exists, but FIFO 2 not");
458 exit(1); 463 exit(1);
@@ -472,6 +477,9 @@ testmode(int argc, char *argv[])
472 477
473 // fork 478 // fork
474 479
480 fd[0] = STDIN_FILENO;
481 fd[1] = STDOUT_FILENO;
482
475 if ((pid = fork()) < 0) 483 if ((pid = fork()) < 0)
476 { 484 {
477 perror("FORK ERROR"); 485 perror("FORK ERROR");
@@ -488,6 +496,10 @@ testmode(int argc, char *argv[])
488 } 496 }
489 else if (pid == 0) // CHILD PROCESS 497 else if (pid == 0) // CHILD PROCESS
490 { 498 {
499
500 signal(SIGINT, sigfunc);
501 signal(SIGTERM, sigfunc);
502 signal(SIGKILL, sigfunc);
491 int rv = 0; 503 int rv = 0;
492 int readc = 0; 504 int readc = 0;
493 int pos = 0; 505 int pos = 0;
@@ -498,7 +510,7 @@ testmode(int argc, char *argv[])
498 readc = 0; 510 readc = 0;
499 511
500 while (readc < sizeof( struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader)){ 512 while (readc < sizeof( struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader)){
501 if ((rv = read(STDIN_FILENO, line, MAXLINE)) < 0) 513 if ((rv = read(fd[0], line, MAXLINE)) < 0)
502 { 514 {
503 perror("READ ERROR FROM STDIN"); 515 perror("READ ERROR FROM STDIN");
504 } 516 }
@@ -526,12 +538,14 @@ testmode(int argc, char *argv[])
526 } 538 }
527 else // PARENT PROCESS 539 else // PARENT PROCESS
528 { 540 {
541 signal(SIGINT, sigfunc);
542 signal(SIGTERM, sigfunc);
543 signal(SIGKILL, sigfunc);
529 int rv = 0; 544 int rv = 0;
530 ssize_t pos = 0; 545 ssize_t pos = 0;
531 char line[MAXLINE]; 546 char line[MAXLINE];
532 struct Wlan_Helper_Control_Message macmsg; 547 struct Wlan_Helper_Control_Message macmsg;
533 548
534
535 //Send random mac address 549 //Send random mac address
536 macmsg.mac.mac[0] = 0x13; 550 macmsg.mac.mac[0] = 0x13;
537 macmsg.mac.mac[1] = 0x22; 551 macmsg.mac.mac[1] = 0x22;
@@ -544,7 +558,7 @@ testmode(int argc, char *argv[])
544 pos = 0; 558 pos = 0;
545 while (pos < sizeof(struct Wlan_Helper_Control_Message)) 559 while (pos < sizeof(struct Wlan_Helper_Control_Message))
546 { 560 {
547 pos += write(STDOUT_FILENO, &macmsg + pos, sizeof(struct Wlan_Helper_Control_Message) - pos); 561 pos += write(fd[1], &macmsg + pos, sizeof(struct Wlan_Helper_Control_Message) - pos);
548 } 562 }
549 563
550 while (closeprog == 0) 564 while (closeprog == 0)
@@ -557,7 +571,7 @@ testmode(int argc, char *argv[])
557 pos = 0; 571 pos = 0;
558 while (pos < rv) 572 while (pos < rv)
559 { 573 {
560 pos += write(STDOUT_FILENO, &line[pos], rv - pos); 574 pos += write(fd[1], &line[pos], rv - pos);
561 } 575 }
562 } 576 }
563 577