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
60 main(int argc, char *argv[])
\r
73 //make the fifos if needed
\r
74 if (stat(FIFO_FILE1, &st) != 0)
\r
76 if (stat(FIFO_FILE2, &st2) == 0)
\r
78 perror("FIFO 2 exists, but FIFO 1 not, blub");
\r
84 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
\r
85 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
\r
87 if ((fpin = fopen(FIFO_FILE1, "r")) == NULL)
\r
92 if ((fpout = fopen(FIFO_FILE2, "w")) == NULL)
\r
102 if (stat(FIFO_FILE2, &st2) != 0)
\r
104 perror("FIFO 1 exists, but FIFO 2 not, mäh");
\r
107 if ((fpout = fopen(FIFO_FILE1, "w")) == NULL)
\r
112 if ((fpin = fopen(FIFO_FILE2, "r")) == NULL)
\r
122 if ((pid = fork()) < 0)
\r
124 perror("FORK ERROR");
\r
129 unlink(FIFO_FILE1);
\r
130 unlink(FIFO_FILE2);
\r
136 else if (pid == 0) // CHILD PROCESS
\r
139 signal(SIGINT, sigfunc);
\r
140 signal(SIGTERM, sigfunc);
\r
141 signal(SIGKILL, sigfunc);
\r
145 char line[MAXLINE];
\r
147 while (closeprog == 0)
\r
151 while (readc < sizeof( struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader)){
\r
152 if ((rv = read(STDIN_FILENO, line, MAXLINE)) < 0)
\r
154 perror("READ ERROR FROM STDIN");
\r
161 //fwrite(&line[pos], 1, sizeof(struct GNUNET_MessageHeader), fpout);
\r
163 //pos += sizeof(struct GNUNET_MessageHeader);
\r
165 //do not send radiotap header
\r
166 pos += sizeof( struct RadiotapHeader);
\r
168 while (pos < readc)
\r
170 pos += fwrite(&line[pos], 1, readc - pos, fpout);
\r
178 else // PARENT PROCESS
\r
181 signal(SIGINT, sigfunc);
\r
182 signal(SIGTERM, sigfunc);
\r
183 signal(SIGKILL, sigfunc);
\r
186 char line[MAXLINE];
\r
187 struct Wlan_Helper_Control_Message macmsg;
\r
190 //Send random mac address
\r
191 macmsg.mac.mac[0] = 0x13;
\r
192 macmsg.mac.mac[1] = 0x22;
\r
193 macmsg.mac.mac[2] = 0x33;
\r
194 macmsg.mac.mac[3] = 0x44;
\r
195 macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255);
\r
196 macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255);
\r
197 macmsg.hdr.size = sizeof(struct Wlan_Helper_Control_Message);
\r
201 while (pos < sizeof(struct Wlan_Helper_Control_Message))
\r
203 pos += write(STDOUT_FILENO, &macmsg + pos, sizeof(struct Wlan_Helper_Control_Message) - pos);
\r
206 while (closeprog == 0)
\r
208 if ((rv = fread(line, 1, MAXLINE, fpin)) < 0)
\r
210 perror("READ ERROR FROM fpin");
\r
216 pos += write(STDOUT_FILENO, &line[pos], rv - pos);
\r
226 unlink(FIFO_FILE1);
\r
227 unlink(FIFO_FILE2);
\r
231 // Write the input to the output
\r