aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c128
-rw-r--r--src/transport/gnunet-transport-wlan-receiver.c42
-rw-r--r--src/transport/gnunet-transport-wlan-sender.c127
3 files changed, 157 insertions, 140 deletions
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index c7ed1b903..0adf8f6a5 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -104,13 +104,14 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
104 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 104 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
105 105
106 GNUNET_memcpy (&macmsg.mac, 106 GNUNET_memcpy (&macmsg.mac,
107 (char *) mac, 107 (char *) mac,
108 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 108 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
109 macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 109 macmsg.hdr.size =
110 htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
110 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 111 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
111 GNUNET_memcpy (buffer, 112 GNUNET_memcpy (buffer,
112 &macmsg, 113 &macmsg,
113 sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 114 sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
114 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); 115 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
115} 116}
116 117
@@ -126,8 +127,7 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
126 * #GNUNET_SYSERR to stop further processing with error 127 * #GNUNET_SYSERR to stop further processing with error
127 */ 128 */
128static int 129static int
129stdin_send (void *cls, 130stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
130 const struct GNUNET_MessageHeader *hdr)
131{ 131{
132 struct SendBuffer *write_pout = cls; 132 struct SendBuffer *write_pout = cls;
133 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; 133 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in;
@@ -137,16 +137,19 @@ stdin_send (void *cls,
137 137
138 sendsize = ntohs (hdr->size); 138 sendsize = ntohs (hdr->size);
139 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; 139 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
140 if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || 140 if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ||
141 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) ) 141 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize))
142 { 142 {
143 fprintf (stderr, "%s", "Received malformed message\n"); 143 fprintf (stderr, "%s", "Received malformed message\n");
144 exit (1); 144 exit (1);
145 } 145 }
146 payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); 146 payload_size =
147 if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) 147 sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
148 if ((payload_size +
149 sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) +
150 write_pout->size) > MAXLINE * 2)
148 { 151 {
149 fprintf (stderr, "%s", "Packet too big for buffer\n"); 152 fprintf (stderr, "%s", "Packet too big for buffer\n");
150 exit (1); 153 exit (1);
151 } 154 }
152 memset (&newheader, 0, sizeof (newheader)); 155 memset (&newheader, 0, sizeof (newheader));
@@ -154,12 +157,10 @@ stdin_send (void *cls,
154 newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); 157 newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
155 newheader.frame = in->frame; 158 newheader.frame = in->frame;
156 GNUNET_memcpy (write_pout->buf + write_pout->size, 159 GNUNET_memcpy (write_pout->buf + write_pout->size,
157 &newheader, 160 &newheader,
158 sizeof (newheader)); 161 sizeof (newheader));
159 write_pout->size += sizeof (newheader); 162 write_pout->size += sizeof (newheader);
160 GNUNET_memcpy (write_pout->buf + write_pout->size, 163 GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size);
161 &in[1],
162 payload_size);
163 write_pout->size += payload_size; 164 write_pout->size += payload_size;
164 return GNUNET_OK; 165 return GNUNET_OK;
165} 166}
@@ -175,8 +176,7 @@ stdin_send (void *cls,
175 * #GNUNET_SYSERR to stop further processing with error 176 * #GNUNET_SYSERR to stop further processing with error
176 */ 177 */
177static int 178static int
178file_in_send (void *cls, 179file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr)
179 const struct GNUNET_MessageHeader *hdr)
180{ 180{
181 struct SendBuffer *write_std = cls; 181 struct SendBuffer *write_std = cls;
182 uint16_t sendsize; 182 uint16_t sendsize;
@@ -224,45 +224,46 @@ main (int argc, char *argv[])
224 struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr; 224 struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr;
225 int first; 225 int first;
226 226
227 if ( (2 != argc) || 227 if ((2 != argc) ||
228 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) ) 228 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))))
229 { 229 {
230 fprintf (stderr, 230 fprintf (
231 "%s", 231 stderr,
232 "This program must be started with the operating mode (1 or 2) as the only argument.\n"); 232 "%s",
233 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
233 return 1; 234 return 1;
234 } 235 }
235 236
236 /* make the fifos if needed */ 237 /* make the fifos if needed */
237 umask (0); 238 umask (0);
238 if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || 239 if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
239 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) ) 240 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)))
240 { 241 {
241 fprintf (stderr, 242 fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
242 "Failed to create directory for file `%s'\n",
243 FIFO_FILE1);
244 return 1; 243 return 1;
245 } 244 }
246 if (0 == strcmp (argv[1], "1") ) 245 if (0 == strcmp (argv[1], "1"))
247 { 246 {
248 if (0 != stat (FIFO_FILE1, &st)) 247 if (0 != stat (FIFO_FILE1, &st))
249 { 248 {
250 erg = mkfifo (FIFO_FILE1, 0666); 249 erg = mkfifo (FIFO_FILE1, 0666);
251 if ( (0 != erg) && (EEXIST != errno) ) 250 if ((0 != erg) && (EEXIST != errno))
252 fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1, 251 fprintf (stderr,
253 strerror (errno)); 252 "Error in mkfifo(%s): %s\n",
253 FIFO_FILE1,
254 strerror (errno));
254 } 255 }
255 } 256 }
256 else 257 else
257 { 258 {
258 if (0 != stat (FIFO_FILE2, &st)) 259 if (0 != stat (FIFO_FILE2, &st))
259 { 260 {
260 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); 261 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666)));
261 if ( (0 != erg) && (EEXIST != errno) ) 262 if ((0 != erg) && (EEXIST != errno))
262 fprintf (stderr, 263 fprintf (stderr,
263 "Error in mkfifo(%s): %s\n", 264 "Error in mkfifo(%s): %s\n",
264 FIFO_FILE2, 265 FIFO_FILE2,
265 strerror (errno)); 266 strerror (errno));
266 } 267 }
267 } 268 }
268 269
@@ -274,7 +275,7 @@ main (int argc, char *argv[])
274 { 275 {
275 fprintf (stderr, 276 fprintf (stderr,
276 "fopen of read FIFO_FILE1 failed: %s\n", 277 "fopen of read FIFO_FILE1 failed: %s\n",
277 STRERROR (errno)); 278 strerror (errno));
278 goto end; 279 goto end;
279 } 280 }
280 if (NULL == (fpout = fopen (FIFO_FILE2, "w"))) 281 if (NULL == (fpout = fopen (FIFO_FILE2, "w")))
@@ -286,7 +287,7 @@ main (int argc, char *argv[])
286 { 287 {
287 fprintf (stderr, 288 fprintf (stderr,
288 "fopen of write FIFO_FILE2 failed: %s\n", 289 "fopen of write FIFO_FILE2 failed: %s\n",
289 STRERROR (errno)); 290 strerror (errno));
290 goto end; 291 goto end;
291 } 292 }
292 } 293 }
@@ -295,14 +296,14 @@ main (int argc, char *argv[])
295 first = 0; 296 first = 0;
296 if (NULL == (fpout = fopen (FIFO_FILE1, "w"))) 297 if (NULL == (fpout = fopen (FIFO_FILE1, "w")))
297 { 298 {
298 GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); 299 GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666));
299 fpout = fopen (FIFO_FILE1, "w"); 300 fpout = fopen (FIFO_FILE1, "w");
300 } 301 }
301 if (NULL == fpout) 302 if (NULL == fpout)
302 { 303 {
303 fprintf (stderr, 304 fprintf (stderr,
304 "fopen of write FIFO_FILE1 failed: %s\n", 305 "fopen of write FIFO_FILE1 failed: %s\n",
305 STRERROR (errno)); 306 strerror (errno));
306 goto end; 307 goto end;
307 } 308 }
308 fpin = fopen (FIFO_FILE2, "r"); 309 fpin = fopen (FIFO_FILE2, "r");
@@ -310,7 +311,7 @@ main (int argc, char *argv[])
310 { 311 {
311 fprintf (stderr, 312 fprintf (stderr,
312 "fopen of read FIFO_FILE2 failed: %s\n", 313 "fopen of read FIFO_FILE2 failed: %s\n",
313 STRERROR (errno)); 314 strerror (errno));
314 goto end; 315 goto end;
315 } 316 }
316 } 317 }
@@ -395,21 +396,22 @@ main (int argc, char *argv[])
395 continue; 396 continue;
396 if (0 > retval) 397 if (0 > retval)
397 { 398 {
398 fprintf (stderr, "select failed: %s\n", STRERROR (errno)); 399 fprintf (stderr, "select failed: %s\n", strerror (errno));
399 closeprog = 1; 400 closeprog = 1;
400 break; 401 break;
401 } 402 }
402 403
403 if (FD_ISSET (STDOUT_FILENO, &wfds)) 404 if (FD_ISSET (STDOUT_FILENO, &wfds))
404 { 405 {
405 ret = 406 ret = write (STDOUT_FILENO,
406 write (STDOUT_FILENO, write_std.buf + write_std.pos, 407 write_std.buf + write_std.pos,
407 write_std.size - write_std.pos); 408 write_std.size - write_std.pos);
408 if (0 > ret) 409 if (0 > ret)
409 { 410 {
410 closeprog = 1; 411 closeprog = 1;
411 fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n", 412 fprintf (stderr,
412 STRERROR (errno)); 413 "Write ERROR to STDOUT_FILENO: %s\n",
414 strerror (errno));
413 break; 415 break;
414 } 416 }
415 else 417 else
@@ -426,14 +428,16 @@ main (int argc, char *argv[])
426 428
427 if (FD_ISSET (fdpout, &wfds)) 429 if (FD_ISSET (fdpout, &wfds))
428 { 430 {
429 ret = 431 ret = write (fdpout,
430 write (fdpout, write_pout.buf + write_pout.pos, 432 write_pout.buf + write_pout.pos,
431 write_pout.size - write_pout.pos); 433 write_pout.size - write_pout.pos);
432 434
433 if (0 > ret) 435 if (0 > ret)
434 { 436 {
435 closeprog = 1; 437 closeprog = 1;
436 fprintf (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno)); 438 fprintf (stderr,
439 "Write ERROR to fdpout failed: %s\n",
440 strerror (errno));
437 } 441 }
438 else 442 else
439 { 443 {
@@ -454,15 +458,17 @@ main (int argc, char *argv[])
454 if (0 > readsize) 458 if (0 > readsize)
455 { 459 {
456 closeprog = 1; 460 closeprog = 1;
457 fprintf (stderr, "Error reading from STDIN_FILENO: %s\n", 461 fprintf (stderr,
458 STRERROR (errno)); 462 "Error reading from STDIN_FILENO: %s\n",
463 strerror (errno));
459 } 464 }
460 else if (0 < readsize) 465 else if (0 < readsize)
461 { 466 {
462 GNUNET_MST_from_buffer (stdin_mst, 467 GNUNET_MST_from_buffer (stdin_mst,
463 readbuf, readsize, 468 readbuf,
464 GNUNET_NO, GNUNET_NO); 469 readsize,
465 470 GNUNET_NO,
471 GNUNET_NO);
466 } 472 }
467 else 473 else
468 { 474 {
@@ -477,14 +483,16 @@ main (int argc, char *argv[])
477 if (0 > readsize) 483 if (0 > readsize)
478 { 484 {
479 closeprog = 1; 485 closeprog = 1;
480 fprintf (stderr, "Error reading from fdpin: %s\n", STRERROR (errno)); 486 fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno));
481 break; 487 break;
482 } 488 }
483 else if (0 < readsize) 489 else if (0 < readsize)
484 { 490 {
485 GNUNET_MST_from_buffer (file_in_mst, 491 GNUNET_MST_from_buffer (file_in_mst,
486 readbuf, readsize, 492 readbuf,
487 GNUNET_NO, GNUNET_NO); 493 readsize,
494 GNUNET_NO,
495 GNUNET_NO);
488 } 496 }
489 else 497 else
490 { 498 {
diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c
index 04f30a683..9b31377e7 100644
--- a/src/transport/gnunet-transport-wlan-receiver.c
+++ b/src/transport/gnunet-transport-wlan-receiver.c
@@ -37,7 +37,7 @@ main (int argc, char *argv[])
37 time_t akt; 37 time_t akt;
38 ssize_t ret; 38 ssize_t ret;
39 pid_t pid; 39 pid_t pid;
40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */ 40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */
41 41
42 if (2 != argc) 42 if (2 != argc)
43 { 43 {
@@ -46,34 +46,30 @@ main (int argc, char *argv[])
46 fprintf (stderr, 46 fprintf (stderr,
47 "Usage: %s interface-name\n" 47 "Usage: %s interface-name\n"
48 "e.g. %s mon0\n", 48 "e.g. %s mon0\n",
49 argv[0], argv[0]); 49 argv[0],
50 argv[0]);
50 return 1; 51 return 1;
51 } 52 }
52 53
53 /* Setup communication pipeline first */ 54 /* Setup communication pipeline first */
54 if (pipe (commpipe)) 55 if (pipe (commpipe))
55 { 56 {
56 fprintf (stderr, 57 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
57 "Failed to create pipe: %s\n",
58 STRERROR (errno));
59 exit (1); 58 exit (1);
60 } 59 }
61 60
62 /* Attempt to fork and check for errors */ 61 /* Attempt to fork and check for errors */
63 if ((pid = fork ()) == -1) 62 if ((pid = fork ()) == -1)
64 { 63 {
65 fprintf (stderr, "Failed to fork: %s\n", 64 fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
66 STRERROR (errno));
67 exit (1); 65 exit (1);
68 } 66 }
69 67
70 if (pid) 68 if (pid)
71 { 69 {
72 /* A positive (non-negative) PID indicates the parent process */ 70 /* A positive (non-negative) PID indicates the parent process */
73 if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */ 71 if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */
74 fprintf (stderr, 72 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
75 "Failed to close fd: %s\n",
76 strerror (errno));
77 start = time (NULL); 73 start = time (NULL);
78 count = 0; 74 count = 0;
79 while (1) 75 while (1)
@@ -81,18 +77,18 @@ main (int argc, char *argv[])
81 ret = read (commpipe[0], msg_buf, sizeof (msg_buf)); 77 ret = read (commpipe[0], msg_buf, sizeof (msg_buf));
82 if (0 > ret) 78 if (0 > ret)
83 { 79 {
84 fprintf (stderr, "read failed: %s\n", strerror (errno)); 80 fprintf (stderr, "read failed: %s\n", strerror (errno));
85 break; 81 break;
86 } 82 }
87 count += ret; 83 count += ret;
88 akt = time (NULL); 84 akt = time (NULL);
89 if (akt - start > 30) 85 if (akt - start > 30)
90 { 86 {
91 bytes_per_s = count / (akt - start); 87 bytes_per_s = count / (akt - start);
92 bytes_per_s /= 1024; 88 bytes_per_s /= 1024;
93 printf ("recv %f kb/s\n", bytes_per_s); 89 printf ("recv %f kb/s\n", bytes_per_s);
94 start = akt; 90 start = akt;
95 count = 0; 91 count = 0;
96 } 92 }
97 } 93 }
98 } 94 }
@@ -100,13 +96,15 @@ main (int argc, char *argv[])
100 { 96 {
101 /* A zero PID indicates that this is the child process */ 97 /* A zero PID indicates that this is the child process */
102 (void) close (1); 98 (void) close (1);
103 if (-1 == dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ 99 if (-1 ==
100 dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */
104 fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); 101 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
105 (void) close (commpipe[0]); /* Close unused side of pipe (in side) */ 102 (void) close (commpipe[0]); /* Close unused side of pipe (in side) */
106 /* Replace the child fork with a new process */ 103 /* Replace the child fork with a new process */
107 if (execlp 104 if (execlp ("gnunet-helper-transport-wlan",
108 ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan", 105 "gnunet-helper-transport-wlan",
109 argv[1], NULL) == -1) 106 argv[1],
107 NULL) == -1)
110 { 108 {
111 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); 109 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
112 _exit (1); 110 _exit (1);
diff --git a/src/transport/gnunet-transport-wlan-sender.c b/src/transport/gnunet-transport-wlan-sender.c
index 36d26f8dc..36273f765 100644
--- a/src/transport/gnunet-transport-wlan-sender.c
+++ b/src/transport/gnunet-transport-wlan-sender.c
@@ -35,16 +35,16 @@
35#define WLAN_LLC_DSAP_FIELD 0x1f 35#define WLAN_LLC_DSAP_FIELD 0x1f
36#define WLAN_LLC_SSAP_FIELD 0x1f 36#define WLAN_LLC_SSAP_FIELD 0x1f
37 37
38#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ 38#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
39 39
40#define IEEE80211_FC0_VERSION_MASK 0x03 40#define IEEE80211_FC0_VERSION_MASK 0x03
41#define IEEE80211_FC0_VERSION_SHIFT 0 41#define IEEE80211_FC0_VERSION_SHIFT 0
42#define IEEE80211_FC0_VERSION_0 0x00 42#define IEEE80211_FC0_VERSION_0 0x00
43#define IEEE80211_FC0_TYPE_MASK 0x0c 43#define IEEE80211_FC0_TYPE_MASK 0x0c
44#define IEEE80211_FC0_TYPE_SHIFT 2 44#define IEEE80211_FC0_TYPE_SHIFT 2
45#define IEEE80211_FC0_TYPE_MGT 0x00 45#define IEEE80211_FC0_TYPE_MGT 0x00
46#define IEEE80211_FC0_TYPE_CTL 0x04 46#define IEEE80211_FC0_TYPE_CTL 0x04
47#define IEEE80211_FC0_TYPE_DATA 0x08 47#define IEEE80211_FC0_TYPE_DATA 0x08
48 48
49 49
50/** 50/**
@@ -55,7 +55,7 @@
55 */ 55 */
56static int 56static int
57getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, 57getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
58 uint16_t size) 58 uint16_t size)
59{ 59{
60 header->header.size = htons (size); 60 header->header.size = htons (size);
61 header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); 61 header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
@@ -75,8 +75,9 @@ getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
75 */ 75 */
76static int 76static int
77getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, 77getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header,
78 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, 78 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
79 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, unsigned int size) 79 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac,
80 unsigned int size)
80{ 81{
81 const int rate = 11000000; 82 const int rate = 11000000;
82 83
@@ -109,21 +110,27 @@ main (int argc, char *argv[])
109 int i; 110 int i;
110 ssize_t ret; 111 ssize_t ret;
111 pid_t pid; 112 pid_t pid;
112 int commpipe[2]; /* This holds the fd for the input & output of the pipe */ 113 int commpipe[2]; /* This holds the fd for the input & output of the pipe */
113 int macpipe[2]; /* This holds the fd for the input & output of the pipe */ 114 int macpipe[2]; /* This holds the fd for the input & output of the pipe */
114 115
115 if (4 != argc) 116 if (4 != argc)
116 { 117 {
117 fprintf (stderr, 118 fprintf (
118 "This program must be started with the interface and the targets and source mac as argument.\n"); 119 stderr,
120 "This program must be started with the interface and the targets and source mac as argument.\n");
119 fprintf (stderr, 121 fprintf (stderr,
120 "Usage: interface-name mac-DST mac-SRC\n" 122 "Usage: interface-name mac-DST mac-SRC\n"
121 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); 123 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
122 return 1; 124 return 1;
123 } 125 }
124 if (6 != 126 if (6 != SSCANF (argv[2],
125 SSCANF (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], 127 "%x-%x-%x-%x-%x-%x",
126 &temp[3], &temp[4], &temp[5])) 128 &temp[0],
129 &temp[1],
130 &temp[2],
131 &temp[3],
132 &temp[4],
133 &temp[5]))
127 { 134 {
128 fprintf (stderr, 135 fprintf (stderr,
129 "Usage: interface-name mac-DST mac-SRC\n" 136 "Usage: interface-name mac-DST mac-SRC\n"
@@ -132,9 +139,14 @@ main (int argc, char *argv[])
132 } 139 }
133 for (i = 0; i < 6; i++) 140 for (i = 0; i < 6; i++)
134 outmac.mac[i] = temp[i]; 141 outmac.mac[i] = temp[i];
135 if (6 != 142 if (6 != SSCANF (argv[3],
136 SSCANF (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], 143 "%x-%x-%x-%x-%x-%x",
137 &temp[3], &temp[4], &temp[5])) 144 &temp[0],
145 &temp[1],
146 &temp[2],
147 &temp[3],
148 &temp[4],
149 &temp[5]))
138 { 150 {
139 fprintf (stderr, 151 fprintf (stderr,
140 "Usage: interface-name mac-DST mac-SRC\n" 152 "Usage: interface-name mac-DST mac-SRC\n"
@@ -148,51 +160,47 @@ main (int argc, char *argv[])
148 /* Setup communication pipeline first */ 160 /* Setup communication pipeline first */
149 if (pipe (commpipe)) 161 if (pipe (commpipe))
150 { 162 {
151 fprintf (stderr, 163 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
152 "Failed to create pipe: %s\n",
153 STRERROR (errno));
154 exit (1); 164 exit (1);
155 } 165 }
156 if (pipe (macpipe)) 166 if (pipe (macpipe))
157 { 167 {
158 fprintf (stderr, 168 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
159 "Failed to create pipe: %s\n",
160 STRERROR (errno));
161 exit (1); 169 exit (1);
162 } 170 }
163 171
164 /* Attempt to fork and check for errors */ 172 /* Attempt to fork and check for errors */
165 if ((pid = fork ()) == -1) 173 if ((pid = fork ()) == -1)
166 { 174 {
167 fprintf (stderr, "Failed to fork: %s\n", 175 fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
168 STRERROR (errno));
169 exit (1); 176 exit (1);
170 } 177 }
171 memset (msg_buf, 0x42, sizeof (msg_buf)); 178 memset (msg_buf, 0x42, sizeof (msg_buf));
172 if (pid) 179 if (pid)
173 { 180 {
174 /* A positive (non-negative) PID indicates the parent process */ 181 /* A positive (non-negative) PID indicates the parent process */
175 if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */ 182 if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */
176 fprintf (stderr, 183 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
177 "Failed to close fd: %s\n", 184 setvbuf (stdout,
178 strerror (errno)); 185 (char *) NULL,
179 setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */ 186 _IONBF,
187 0); /* Set non-buffered output on stdout */
180 188
181 if (0 != close (macpipe[1])) 189 if (0 != close (macpipe[1]))
182 fprintf (stderr, 190 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
183 "Failed to close fd: %s\n",
184 strerror (errno));
185 if (sizeof (hcm) != read (macpipe[0], &hcm, sizeof (hcm))) 191 if (sizeof (hcm) != read (macpipe[0], &hcm, sizeof (hcm)))
186 fprintf (stderr, 192 fprintf (stderr, "Failed to read hcm...\n");
187 "Failed to read hcm...\n");
188 fprintf (stderr, 193 fprintf (stderr,
189 "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", 194 "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
190 hcm.mac.mac[0], hcm.mac.mac[1], 195 hcm.mac.mac[0],
191 hcm.mac.mac[2], hcm.mac.mac[3], hcm.mac.mac[4], hcm.mac.mac[5]); 196 hcm.mac.mac[1],
197 hcm.mac.mac[2],
198 hcm.mac.mac[3],
199 hcm.mac.mac[4],
200 hcm.mac.mac[5]);
192 radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf; 201 radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf;
193 getRadiotapHeader (radiotap, WLAN_MTU); 202 getRadiotapHeader (radiotap, WLAN_MTU);
194 getWlanHeader (&radiotap->frame, &outmac, &inmac, 203 getWlanHeader (&radiotap->frame, &outmac, &inmac, WLAN_MTU);
195 WLAN_MTU);
196 start = time (NULL); 204 start = time (NULL);
197 count = 0; 205 count = 0;
198 while (1) 206 while (1)
@@ -200,18 +208,18 @@ main (int argc, char *argv[])
200 ret = write (commpipe[1], msg_buf, WLAN_MTU); 208 ret = write (commpipe[1], msg_buf, WLAN_MTU);
201 if (0 > ret) 209 if (0 > ret)
202 { 210 {
203 fprintf (stderr, "write failed: %s\n", strerror (errno)); 211 fprintf (stderr, "write failed: %s\n", strerror (errno));
204 break; 212 break;
205 } 213 }
206 count += ret; 214 count += ret;
207 akt = time (NULL); 215 akt = time (NULL);
208 if (akt - start > 30) 216 if (akt - start > 30)
209 { 217 {
210 bytes_per_s = count / (akt - start); 218 bytes_per_s = count / (akt - start);
211 bytes_per_s /= 1024; 219 bytes_per_s /= 1024;
212 printf ("send %f kbytes/s\n", bytes_per_s); 220 printf ("send %f kbytes/s\n", bytes_per_s);
213 start = akt; 221 start = akt;
214 count = 0; 222 count = 0;
215 } 223 }
216 } 224 }
217 } 225 }
@@ -220,16 +228,19 @@ main (int argc, char *argv[])
220 /* A zero PID indicates that this is the child process */ 228 /* A zero PID indicates that this is the child process */
221 (void) close (0); 229 (void) close (0);
222 (void) close (1); 230 (void) close (1);
223 if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ 231 if (-1 ==
232 dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */
224 fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); 233 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
225 if (-1 == dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */ 234 if (-1 ==
235 dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */
226 fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); 236 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
227 (void) close (commpipe[1]); /* Close unused side of pipe (out side) */ 237 (void) close (commpipe[1]); /* Close unused side of pipe (out side) */
228 (void) close (macpipe[0]); /* Close unused side of pipe (in side) */ 238 (void) close (macpipe[0]); /* Close unused side of pipe (in side) */
229 /* Replace the child fork with a new process */ 239 /* Replace the child fork with a new process */
230 if (execlp 240 if (execlp ("gnunet-helper-transport-wlan",
231 ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan", 241 "gnunet-helper-transport-wlan",
232 argv[1], NULL) == -1) 242 argv[1],
243 NULL) == -1)
233 { 244 {
234 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); 245 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
235 _exit (1); 246 _exit (1);