aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/Makefile.am9
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c3
-rw-r--r--src/transport/plugin_transport_wlan.h4
-rw-r--r--src/transport/test_plugin_transport_wlan_dummy.c282
4 files changed, 204 insertions, 94 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index e616c9d19..f1f72b689 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -77,10 +77,14 @@ bin_SCRIPTS = \
77gnunet_nat_server_SOURCES = \ 77gnunet_nat_server_SOURCES = \
78 $(NATSERVER) 78 $(NATSERVER)
79 79
80
80gnunet_transport_wlan_helper_SOURCES = \ 81gnunet_transport_wlan_helper_SOURCES = \
81 gnunet-transport-wlan-helper.c 82 gnunet-transport-wlan-helper.c
82gnunet_transport_wlan_helper_LDADD = \ 83gnunet_transport_wlan_helper_LDADD = \
83 -lpcap 84 -lpcap
85
86test_plugin_transport_wlan_SOURCES = \
87 test_plugin_transport_wlan_dummy.c
84 88
85gnunet_nat_client_SOURCES = \ 89gnunet_nat_client_SOURCES = \
86 $(NATCLIENT) 90 $(NATCLIENT)
@@ -215,7 +219,8 @@ check_PROGRAMS = \
215 test_quota_compliance_udp \ 219 test_quota_compliance_udp \
216 test_quota_compliance_udp_asymmetric_recv_constant \ 220 test_quota_compliance_udp_asymmetric_recv_constant \
217 $(HTTP_QUOTA_TEST) \ 221 $(HTTP_QUOTA_TEST) \
218 $(HTTPS_QUOTA_TEST) 222 $(HTTPS_QUOTA_TEST) \
223 test_plugin_transport_wlan
219# TODO: add tests for nat, etc. 224# TODO: add tests for nat, etc.
220 225
221if !DISABLE_TEST_RUN 226if !DISABLE_TEST_RUN
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 7556e6663..87c140825 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -33,6 +33,8 @@
33 33
34#include <pcap.h> 34#include <pcap.h>
35 35
36
37
36//#include "radiotap.h" 38//#include "radiotap.h"
37 39
38// mac of this node 40// mac of this node
@@ -643,3 +645,4 @@ main(int argc, char *argv[])
643 645
644 return (0); 646 return (0);
645} 647}
648
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h
index 1444af18e..3c206a496 100644
--- a/src/transport/plugin_transport_wlan.h
+++ b/src/transport/plugin_transport_wlan.h
@@ -24,6 +24,9 @@
24 * @author David Brodski 24 * @author David Brodski
25 */ 25 */
26 26
27#ifndef PLUGIN_TRANSPORT_WLAN
28#define PLUGIN_TRANSPORT_WLAN
29
27#include "gnunet_common.h" 30#include "gnunet_common.h"
28 31
29typedef unsigned int uint32_t; 32typedef unsigned int uint32_t;
@@ -163,3 +166,4 @@ struct RadiotapHeader
163 uint8_t antenna; 166 uint8_t antenna;
164}; 167};
165 168
169#endif
diff --git a/src/transport/test_plugin_transport_wlan_dummy.c b/src/transport/test_plugin_transport_wlan_dummy.c
index 4afb24ed4..adfada461 100644
--- a/src/transport/test_plugin_transport_wlan_dummy.c
+++ b/src/transport/test_plugin_transport_wlan_dummy.c
@@ -1,99 +1,197 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_wlan_dummy.c 21 * @file transport/test_transport_wlan_dummy.c
22 * @brief helper for the testcase for plugin_transport_wlan.c 22 * @brief helper for the testcase for plugin_transport_wlan.c
23 * @author David Brodski 23 * @author David Brodski
24 */ 24 */
25 25
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_constants.h" 27#include "gnunet_constants.h"
28#include "gnunet_os_lib.h" 28#include "gnunet_os_lib.h"
29#include "gnunet_transport_plugin.h" 29#include "gnunet_transport_plugin.h"
30#include "transport.h" 30#include "transport.h"
31#include "plugin_transport_wlan.h" 31#include "plugin_transport_wlan.h"
32#include "gnunet_common.h" 32#include "gnunet_common.h"
33#include "gnunet-transport-wlan-helper.h" 33#include "gnunet-transport-wlan-helper.h"
34#include "plugin_transport_wlan.h" 34
35
36#include <stdio.h> 35#include <stdio.h>
37#include <stdlib.h> 36#include <stdlib.h>
38#include <sys/stat.h> 37#include <sys/stat.h>
39 38
40#define FIFO_FILE1 "MYFIFOin" 39#define FIFO_FILE1 "MYFIFOin"
41#define FIFO_FILE2 "MYFIFOout" 40#define FIFO_FILE2 "MYFIFOout"
42 41#define MAXLINE 5000
43int 42
44main(int argc, char *argv[]) 43int closeprog = 0;
45{ 44
46 struct stat st; 45void sigfunc(int sig)
47 int erg; 46{
48 int first; 47
49 FILE *fpin; 48 if(sig != SIGINT || sig != SIGTERM || sig != SIGKILL)
50 FILE *fpout; 49 return;
51 //make the fifos if needed 50 else
52 if(stat(FIFO_FILE1,&st) != 0){ 51 {
53 if(stat(FIFO_FILE2,&st) != 0){ 52 closeprog = 1;
54 perror("FIFO 2 exists, but FIFO 1 not"); 53 }
55 exit(1);
56 }
57 first = 1;
58 umask(0);
59 erg = mknod(FIFO_FILE1, S_IFIFO|0666, 0);
60 erg = mknod(FIFO_FILE2, S_IFIFO|0666, 0);
61
62 if((fpin = fopen(FIFO_FILE1, "r")) == NULL) {
63 perror("fopen");
64 exit(1);
65 }
66 if((fpout = fopen(FIFO_FILE2, "w")) == NULL) {
67 perror("fopen");
68 exit(1);
69 }
70 } else {
71 first = 0;
72 if(stat(FIFO_FILE2,&st) == 0){
73 perror("FIFO 1 exists, but FIFO 2 not");
74 exit(1);
75 }
76 if((fpout = fopen(FIFO_FILE1, "w")) == NULL) {
77 perror("fopen");
78 exit(1);
79 }
80 if((fpin = fopen(FIFO_FILE2, "r")) == NULL) {
81 perror("fopen");
82 exit(1);
83 }
84
85 }
86 // Write the input to the output
87
88 //clean up
89 if (first == 1){
90 unlink(FIFO_FILE1);
91 unlink(FIFO_FILE2);
92 }
93
94
95 fclose(fpin);
96 fclose(fpout);
97 return(0);
98} 54}
99 55
56
57
58int
59main(int argc, char *argv[])
60{
61 struct stat st;
62 int erg;
63 int first;
64 FILE *fpin;
65 FILE *fpout;
66 pid_t pid;
67
68 signal(SIGINT,sigfunc);
69 signal(SIGTERM,sigfunc);
70 signal(SIGKILL,sigfunc);
71
72 //make the fifos if needed
73 if (stat(FIFO_FILE1, &st) != 0)
74 {
75 if (stat(FIFO_FILE2, &st) != 0)
76 {
77 perror("FIFO 2 exists, but FIFO 1 not");
78 exit(1);
79 }
80 first = 1;
81 umask(0);
82 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
83 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
84
85 if ((fpin = fopen(FIFO_FILE1, "r")) == NULL)
86 {
87 perror("fopen");
88 exit(1);
89 }
90 if ((fpout = fopen(FIFO_FILE2, "w")) == NULL)
91 {
92 perror("fopen");
93 exit(1);
94 }
95 }
96 else
97 {
98 first = 0;
99 if (stat(FIFO_FILE2, &st) == 0)
100 {
101 perror("FIFO 1 exists, but FIFO 2 not");
102 exit(1);
103 }
104 if ((fpout = fopen(FIFO_FILE1, "w")) == NULL)
105 {
106 perror("fopen");
107 exit(1);
108 }
109 if ((fpin = fopen(FIFO_FILE2, "r")) == NULL)
110 {
111 perror("fopen");
112 exit(1);
113 }
114
115 }
116
117 // fork
118
119 if ((pid = fork()) < 0)
120 {
121 perror("FORK ERROR");
122 return -3;
123 }
124 else if (pid == 0) // CHILD PROCESS
125 {
126 int rv = 0;
127 int read = 0;
128 int pos = 0;
129 char line[MAXLINE];
130
131 while (closeprog == 0)
132 {
133 read = 0;
134
135 while (read < sizeof( struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader)){
136 if ((rv = read(STDIN_FILENO, line, MAXLINE)) < 0)
137 {
138 perror("READ ERROR FROM STDIN");
139 }
140 read += rv;
141 }
142
143 pos = 0;
144
145 fwrite(&line[pos], 1, sizeof(struct GNUNET_MessageHeader), fpout);
146
147 pos += sizeof(struct GNUNET_MessageHeader);
148
149 //do not send radiotap header
150 pos += sizeof( struct RadiotapHeader);
151
152 while (pos < read)
153 {
154 pos += fwrite(&line[pos], 1, read - pos, fpout);
155 }
156 }
157
158
159 //clean up
160 fclose(fpout);
161 }
162 else // PARENT PROCESS
163 {
164 int rv = 0;
165 ssize_t pos = 0;
166 char line[MAXLINE];
167
168 while (closeprog == 0)
169 {
170 if ((rv = fread(line, 1, MAXLINE, fpin)) < 0)
171 {
172 perror("READ ERROR FROM STDIN");
173 }
174
175 pos = 0;
176 while (pos < rv)
177 {
178 pos += write(STDOUT_FILENO, &line[pos], rv - pos);
179 }
180 }
181
182
183 //clean up
184 fclose(fpin);
185
186 if (first == 1)
187 {
188 unlink(FIFO_FILE1);
189 unlink(FIFO_FILE2);
190 }
191 }
192
193 // Write the input to the output
194
195 return (0);
196}
197