aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport-wlan-helper.c
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-01-23 17:15:21 +0000
committerDavid Brodski <david@brodski.eu>2011-01-23 17:15:21 +0000
commit529055038874c97055e554f83b2fcd8f4f7f0dab (patch)
tree1fef67e4f36d7bc8045badb438682acdfed9ba10 /src/transport/gnunet-transport-wlan-helper.c
parent7fc649b003d105b2fbc31aa7a4d10a60c6d64cfe (diff)
downloadgnunet-529055038874c97055e554f83b2fcd8f4f7f0dab.tar.gz
gnunet-529055038874c97055e554f83b2fcd8f4f7f0dab.zip
Some errors fixed, most of them where buffer-position errors.
Diffstat (limited to 'src/transport/gnunet-transport-wlan-helper.c')
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c71
1 files changed, 47 insertions, 24 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 05fab4758..15fe21cfd 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -38,6 +38,7 @@
38#include "plugin_transport_wlan.h" 38#include "plugin_transport_wlan.h"
39#include "gnunet_common.h" 39#include "gnunet_common.h"
40#include "gnunet-transport-wlan-helper.h" 40#include "gnunet-transport-wlan-helper.h"
41#include "gnunet_crypto_lib.h"
41#include "ieee80211_radiotap.h" 42#include "ieee80211_radiotap.h"
42#include <pcap.h> 43#include <pcap.h>
43#include <stdio.h> 44#include <stdio.h>
@@ -395,7 +396,7 @@ int ieee80211_radiotap_iterator_next(
395 396
396#define FIFO_FILE1 "/tmp/MYFIFOin" 397#define FIFO_FILE1 "/tmp/MYFIFOin"
397#define FIFO_FILE2 "/tmp/MYFIFOout" 398#define FIFO_FILE2 "/tmp/MYFIFOout"
398#define MAXLINE 20 399#define MAXLINE 4096
399 400
400static int first; 401static int first;
401static int closeprog; 402static int closeprog;
@@ -420,22 +421,36 @@ stdin_send (void *cls,
420 const struct GNUNET_MessageHeader *hdr) 421 const struct GNUNET_MessageHeader *hdr)
421{ 422{
422 struct sendbuf *write_pout = cls; 423 struct sendbuf *write_pout = cls;
423 int sendsize = ntohs(hdr->size) - sizeof(struct RadiotapHeader) ; 424 int sendsize;
424 struct GNUNET_MessageHeader newheader; 425 struct GNUNET_MessageHeader newheader;
426 char * from;
427 char * to;
425 428
426 GNUNET_assert(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA == ntohs(hdr->type)); 429 sendsize = ntohs(hdr->size) - sizeof(struct RadiotapHeader) ;
427 GNUNET_assert (sendsize + write_pout->size < MAXLINE *2); 430
431
432 if(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)){
433 fprintf(stderr, "Function stdin_send: wrong packet type\n");
434 exit(1);
435 }
436 if((sendsize + write_pout->size) > MAXLINE * 2){
437 fprintf(stderr, "Function stdin_send: Packet too big for buffer\n");
438 exit(1);
439 }
428 440
429 441
430 newheader.size = htons(sendsize); 442 newheader.size = htons(sendsize);
431 newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 443 newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
432 444
433 445
434 memcpy(write_pout->buf + write_pout->size, &newheader, sizeof(struct GNUNET_MessageHeader)); 446 to = write_pout->buf + write_pout->size;
447 memcpy(to, &newheader, sizeof(struct GNUNET_MessageHeader));
435 write_pout->size += sizeof(struct GNUNET_MessageHeader); 448 write_pout->size += sizeof(struct GNUNET_MessageHeader);
436 449
437 memcpy(write_pout->buf + write_pout->size, hdr + sizeof(struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader), sizeof(struct GNUNET_MessageHeader)); 450 from = (char *) hdr + sizeof(struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader);
438 write_pout->size += sendsize; 451 to = write_pout->buf + write_pout->size;
452 memcpy(to, from, sendsize - sizeof(struct GNUNET_MessageHeader));
453 write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader);
439} 454}
440 455
441static void 456static void
@@ -444,10 +459,18 @@ file_in_send (void *cls,
444 const struct GNUNET_MessageHeader *hdr) 459 const struct GNUNET_MessageHeader *hdr)
445{ 460{
446 struct sendbuf * write_std = cls; 461 struct sendbuf * write_std = cls;
447 int sendsize = ntohs(hdr->size); 462 int sendsize;
463
464 sendsize = ntohs(hdr->size);
448 465
449 GNUNET_assert(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA == ntohs(hdr->type)); 466 if(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)){
450 GNUNET_assert (sendsize + write_std->size < MAXLINE *2); 467 fprintf(stderr, "Function file_in_send: wrong packet type\n");
468 exit(1);
469 }
470 if((sendsize + write_std->size) > MAXLINE * 2){
471 fprintf(stderr, "Function file_in_send: Packet too big for buffer\n");
472 exit(1);
473 }
451 474
452 memcpy(write_std->buf + write_std->size, hdr, sendsize); 475 memcpy(write_std->buf + write_std->size, hdr, sendsize);
453 write_std->size += sendsize; 476 write_std->size += sendsize;
@@ -470,7 +493,7 @@ testmode(int argc, char *argv[])
470 { 493 {
471 if (0 == stat(FIFO_FILE2, &st)) 494 if (0 == stat(FIFO_FILE2, &st))
472 { 495 {
473 fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not"); 496 fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
474 exit(1); 497 exit(1);
475 } 498 }
476 499
@@ -484,7 +507,7 @@ testmode(int argc, char *argv[])
484 507
485 if (0 != stat(FIFO_FILE2, &st)) 508 if (0 != stat(FIFO_FILE2, &st))
486 { 509 {
487 fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not"); 510 fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
488 exit(1); 511 exit(1);
489 } 512 }
490 513
@@ -497,12 +520,12 @@ testmode(int argc, char *argv[])
497 fpin = fopen(FIFO_FILE1, "r"); 520 fpin = fopen(FIFO_FILE1, "r");
498 if (NULL == fpin) 521 if (NULL == fpin)
499 { 522 {
500 fprintf(stderr, "fopen of read FIFO_FILE1"); 523 fprintf(stderr, "fopen of read FIFO_FILE1\n");
501 exit(1); 524 exit(1);
502 } 525 }
503 if (NULL == (fpout = fopen(FIFO_FILE2, "w"))) 526 if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
504 { 527 {
505 fprintf(stderr, "fopen of write FIFO_FILE2"); 528 fprintf(stderr, "fopen of write FIFO_FILE2\n");
506 exit(1); 529 exit(1);
507 } 530 }
508 531
@@ -513,12 +536,12 @@ testmode(int argc, char *argv[])
513 //fprintf(stderr, "Second\n"); 536 //fprintf(stderr, "Second\n");
514 if (NULL == (fpout = fopen(FIFO_FILE1, "w"))) 537 if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
515 { 538 {
516 fprintf(stderr, "fopen of write FIFO_FILE1"); 539 fprintf(stderr, "fopen of write FIFO_FILE1\n");
517 exit(1); 540 exit(1);
518 } 541 }
519 if (NULL == (fpin = fopen(FIFO_FILE2, "r"))) 542 if (NULL == (fpin = fopen(FIFO_FILE2, "r")))
520 { 543 {
521 fprintf(stderr, "fopen of read FIFO_FILE2"); 544 fprintf(stderr, "fopen of read FIFO_FILE2\n");
522 exit(1); 545 exit(1);
523 } 546 }
524 547
@@ -581,8 +604,8 @@ testmode(int argc, char *argv[])
581 macmsg.mac.mac[1] = 0x22; 604 macmsg.mac.mac[1] = 0x22;
582 macmsg.mac.mac[2] = 0x33; 605 macmsg.mac.mac[2] = 0x33;
583 macmsg.mac.mac[3] = 0x44; 606 macmsg.mac.mac[3] = 0x44;
584 macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); 607 macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
585 macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); 608 macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
586 macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message)); 609 macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message));
587 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 610 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
588 611
@@ -690,7 +713,7 @@ testmode(int argc, char *argv[])
690 if (0 > ret) 713 if (0 > ret)
691 { 714 {
692 closeprog = 1; 715 closeprog = 1;
693 fprintf(stderr, "Write ERROR to STDOUT"); 716 fprintf(stderr, "Write ERROR to STDOUT\n");
694 exit(1); 717 exit(1);
695 } 718 }
696 else 719 else
@@ -713,7 +736,7 @@ testmode(int argc, char *argv[])
713 if (0 > ret) 736 if (0 > ret)
714 { 737 {
715 closeprog = 1; 738 closeprog = 1;
716 fprintf(stderr, "Write ERROR to fdpout"); 739 fprintf(stderr, "Write ERROR to fdpout\n");
717 exit(1); 740 exit(1);
718 } 741 }
719 else 742 else
@@ -735,10 +758,10 @@ testmode(int argc, char *argv[])
735 if (0 > readsize) 758 if (0 > readsize)
736 { 759 {
737 closeprog = 1; 760 closeprog = 1;
738 fprintf(stderr, "Read ERROR to STDIN_FILENO"); 761 fprintf(stderr, "Read ERROR to STDIN_FILENO\n");
739 exit(1); 762 exit(1);
740 } 763 }
741 else 764 else if (0 < readsize)
742 { 765 {
743 GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize, 766 GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
744 GNUNET_NO, GNUNET_NO); 767 GNUNET_NO, GNUNET_NO);
@@ -753,10 +776,10 @@ testmode(int argc, char *argv[])
753 if (0 > readsize) 776 if (0 > readsize)
754 { 777 {
755 closeprog = 1; 778 closeprog = 1;
756 fprintf(stderr, "Read ERROR to fdpin"); 779 fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno));
757 exit(1); 780 exit(1);
758 } 781 }
759 else 782 else if (0 < readsize)
760 { 783 {
761 GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, 784 GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
762 GNUNET_NO, GNUNET_NO); 785 GNUNET_NO, GNUNET_NO);