2 This file is part of GNUnet.
\r
3 (C) 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
\r
6 it under the terms of the GNU General Public License as published
\r
7 by the Free Software Foundation; either version 3, or (at your
\r
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
\r
11 WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
\r
16 along with GNUnet; see the file COPYING. If not, write to the
\r
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
\r
18 Boston, MA 02111-1307, USA.
\r
21 * @file transport/test_transport_wlan_dummy.c
\r
22 * @brief helper for the testcase for plugin_transport_wlan.c
\r
23 * @author David Brodski
\r
26 #include "platform.h"
\r
27 #include "gnunet_constants.h"
\r
28 #include "gnunet_os_lib.h"
\r
29 #include "gnunet_transport_plugin.h"
\r
30 #include "transport.h"
\r
31 #include "plugin_transport_wlan.h"
\r
32 #include "gnunet_common.h"
\r
33 #include "gnunet-transport-wlan-helper.h"
\r
37 #include <sys/stat.h>
\r
39 #define FIFO_FILE1 "MYFIFOin"
\r
40 #define FIFO_FILE2 "MYFIFOout"
\r
41 #define MAXLINE 5000
\r
45 void sigfunc(int sig)
\r
48 if(sig != SIGINT || sig != SIGTERM || sig != SIGKILL)
\r
59 main(int argc, char *argv[])
\r
68 signal(SIGINT,sigfunc);
\r
69 signal(SIGTERM,sigfunc);
\r
70 signal(SIGKILL,sigfunc);
\r
72 //make the fifos if needed
\r
73 if (stat(FIFO_FILE1, &st) != 0)
\r
75 if (stat(FIFO_FILE2, &st) != 0)
\r
77 perror("FIFO 2 exists, but FIFO 1 not");
\r
82 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
\r
83 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
\r
85 if ((fpin = fopen(FIFO_FILE1, "r")) == NULL)
\r
90 if ((fpout = fopen(FIFO_FILE2, "w")) == NULL)
\r
99 if (stat(FIFO_FILE2, &st) == 0)
\r
101 perror("FIFO 1 exists, but FIFO 2 not");
\r
104 if ((fpout = fopen(FIFO_FILE1, "w")) == NULL)
\r
109 if ((fpin = fopen(FIFO_FILE2, "r")) == NULL)
\r
119 if ((pid = fork()) < 0)
\r
121 perror("FORK ERROR");
\r
124 else if (pid == 0) // CHILD PROCESS
\r
129 char line[MAXLINE];
\r
131 while (closeprog == 0)
\r
135 while (readc < sizeof( struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader)){
\r
136 if ((rv = read(STDIN_FILENO, line, MAXLINE)) < 0)
\r
138 perror("READ ERROR FROM STDIN");
\r
145 fwrite(&line[pos], 1, sizeof(struct GNUNET_MessageHeader), fpout);
\r
147 pos += sizeof(struct GNUNET_MessageHeader);
\r
149 //do not send radiotap header
\r
150 pos += sizeof( struct RadiotapHeader);
\r
152 while (pos < readc)
\r
154 pos += fwrite(&line[pos], 1, readc - pos, fpout);
\r
162 else // PARENT PROCESS
\r
166 char line[MAXLINE];
\r
168 while (closeprog == 0)
\r
170 if ((rv = fread(line, 1, MAXLINE, fpin)) < 0)
\r
172 perror("READ ERROR FROM STDIN");
\r
178 pos += write(STDOUT_FILENO, &line[pos], rv - pos);
\r
188 unlink(FIFO_FILE1);
\r
189 unlink(FIFO_FILE2);
\r
193 // Write the input to the output
\r