diff options
author | David Brodski <david@brodski.eu> | 2011-05-23 23:14:47 +0000 |
---|---|---|
committer | David Brodski <david@brodski.eu> | 2011-05-23 23:14:47 +0000 |
commit | 5cdc9eb4091dfbfd1d65c4aaf1e3dfdd4b5b6316 (patch) | |
tree | a610fd026af2cde16c0140ca70be37f5913d6a43 /src/transport/test_plugin_transport_wlan_dummy.c | |
parent | 57e5f310b699c0b91dabac940e04ef4b152ee2a3 (diff) | |
download | gnunet-5cdc9eb4091dfbfd1d65c4aaf1e3dfdd4b5b6316.tar.gz gnunet-5cdc9eb4091dfbfd1d65c4aaf1e3dfdd4b5b6316.zip |
Some bugfixes, udp packets can now be send over wlan, unrel test added, clean up
Diffstat (limited to 'src/transport/test_plugin_transport_wlan_dummy.c')
-rw-r--r-- | src/transport/test_plugin_transport_wlan_dummy.c | 492 |
1 files changed, 349 insertions, 143 deletions
diff --git a/src/transport/test_plugin_transport_wlan_dummy.c b/src/transport/test_plugin_transport_wlan_dummy.c index 79f87584d..21cc74aa2 100644 --- a/src/transport/test_plugin_transport_wlan_dummy.c +++ b/src/transport/test_plugin_transport_wlan_dummy.c | |||
@@ -19,241 +19,447 @@ | |||
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 testcases for plugin_transport_wlan.c |
23 | * @author David Brodski | 23 | * @author David Brodski |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <sys/socket.h> | ||
27 | #include <sys/ioctl.h> | ||
28 | #include <sys/types.h> | ||
29 | #include <sys/wait.h> | ||
30 | #include <sys/time.h> | ||
31 | #include <sys/stat.h> | ||
32 | #include <stdio.h> | ||
33 | #include <stdlib.h> | ||
34 | |||
35 | #include <errno.h> | ||
36 | #include <resolv.h> | ||
37 | #include <string.h> | ||
38 | #include <utime.h> | ||
39 | #include <unistd.h> | ||
40 | #include <getopt.h> | ||
41 | |||
26 | #include "platform.h" | 42 | #include "platform.h" |
27 | #include "gnunet_constants.h" | 43 | #include "gnunet_constants.h" |
28 | #include "gnunet_os_lib.h" | 44 | #include "gnunet_os_lib.h" |
29 | #include "gnunet_transport_plugin.h" | 45 | #include "gnunet_transport_plugin.h" |
30 | #include "transport.h" | 46 | #include "transport.h" |
47 | #include "gnunet_util_lib.h" | ||
31 | #include "plugin_transport_wlan.h" | 48 | #include "plugin_transport_wlan.h" |
32 | #include "gnunet_common.h" | 49 | #include "gnunet_common.h" |
33 | #include "gnunet-transport-wlan-helper.h" | 50 | #include "gnunet-transport-wlan-helper.h" |
51 | #include "gnunet_crypto_lib.h" | ||
52 | #include "wlan/loopback_helper.h" | ||
53 | #include "wlan/helper_common.h" | ||
34 | 54 | ||
35 | #include <stdio.h> | 55 | int first; |
36 | #include <stdlib.h> | ||
37 | #include <sys/stat.h> | ||
38 | 56 | ||
39 | #define FIFO_FILE1 "MYFIFOin" | 57 | static void |
40 | #define FIFO_FILE2 "MYFIFOout" | 58 | sigfunc(int sig) |
41 | #define MAXLINE 5000 | 59 | { |
42 | 60 | closeprog = 1; | |
43 | int closeprog = 0; | 61 | unlink(FIFO_FILE1); |
62 | unlink(FIFO_FILE2); | ||
63 | } | ||
44 | 64 | ||
45 | void sigfunc(int sig) | 65 | static void |
66 | stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | ||
46 | { | 67 | { |
68 | struct sendbuf *write_pout = cls; | ||
69 | int sendsize; | ||
70 | struct GNUNET_MessageHeader newheader; | ||
71 | unsigned char * from_data; | ||
72 | unsigned char * to_data; | ||
73 | //unsigned char * from_radiotap; | ||
74 | unsigned char * to_radiotap; | ||
75 | //unsigned char * from_start; | ||
76 | unsigned char * to_start; | ||
77 | |||
78 | sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send) | ||
79 | + sizeof(struct Radiotap_rx); | ||
80 | |||
81 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) | ||
82 | { | ||
83 | fprintf(stderr, "Function stdin_send: wrong packet type\n"); | ||
84 | exit(1); | ||
85 | } | ||
86 | if ((sendsize + write_pout->size) > MAXLINE * 2) | ||
87 | { | ||
88 | fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); | ||
89 | exit(1); | ||
90 | } | ||
47 | 91 | ||
48 | if(sig != SIGINT || sig != SIGTERM || sig != SIGKILL) | 92 | newheader.size = htons(sendsize); |
49 | return; | 93 | newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
50 | else | 94 | |
51 | { | 95 | to_start = write_pout->buf + write_pout->size; |
52 | closeprog = 1; | 96 | to_radiotap = to_start + sizeof(struct GNUNET_MessageHeader); |
53 | exit(0); | 97 | to_data = to_radiotap + sizeof(struct Radiotap_rx); |
54 | } | 98 | |
99 | from_data = ((unsigned char *) hdr) + sizeof(struct Radiotap_Send) | ||
100 | + sizeof(struct GNUNET_MessageHeader); | ||
101 | |||
102 | memcpy(to_start, &newheader, sizeof(struct GNUNET_MessageHeader)); | ||
103 | write_pout->size += sizeof(struct GNUNET_MessageHeader); | ||
104 | |||
105 | write_pout->size += sizeof(struct Radiotap_rx); | ||
106 | |||
107 | memcpy(to_data, from_data, ntohs(hdr->size) - sizeof(struct Radiotap_Send) | ||
108 | - sizeof(struct GNUNET_MessageHeader)); | ||
109 | write_pout->size += ntohs(hdr->size) - sizeof(struct Radiotap_Send) | ||
110 | - sizeof(struct GNUNET_MessageHeader); | ||
55 | } | 111 | } |
56 | 112 | ||
113 | static void | ||
114 | file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | ||
115 | { | ||
116 | struct sendbuf * write_std = cls; | ||
117 | uint16_t sendsize; | ||
57 | 118 | ||
119 | sendsize = ntohs(hdr->size); | ||
120 | |||
121 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) | ||
122 | { | ||
123 | fprintf(stderr, "Function file_in_send: wrong packet type\n"); | ||
124 | exit(1); | ||
125 | } | ||
126 | if ((sendsize + write_std->size) > MAXLINE * 2) | ||
127 | { | ||
128 | fprintf(stderr, "Function file_in_send: Packet too big for buffer\n"); | ||
129 | exit(1); | ||
130 | } | ||
131 | |||
132 | memcpy(write_std->buf + write_std->size, hdr, sendsize); | ||
133 | write_std->size += sendsize; | ||
134 | } | ||
135 | |||
136 | int closeprog; | ||
58 | 137 | ||
59 | 138 | ||
60 | int | 139 | int |
61 | main(int argc, char *argv[]) | 140 | testmode(int argc, char *argv[]) |
62 | { | 141 | { |
63 | struct stat st; | 142 | struct stat st; |
64 | struct stat st2; | ||
65 | int erg; | 143 | int erg; |
66 | int first; | ||
67 | FILE *fpin; | ||
68 | FILE *fpout; | ||
69 | pid_t pid; | ||
70 | 144 | ||
71 | perror("Test"); | 145 | FILE *fpin = NULL; |
146 | FILE *fpout = NULL; | ||
72 | 147 | ||
148 | int fdpin; | ||
149 | int fdpout; | ||
73 | 150 | ||
74 | //make the fifos if needed | 151 | //make the fifos if needed |
75 | if (stat(FIFO_FILE1, &st) != 0) | 152 | if (0 != stat(FIFO_FILE1, &st)) |
76 | { | 153 | { |
77 | if (stat(FIFO_FILE2, &st2) == 0) | 154 | if (0 == stat(FIFO_FILE2, &st)) |
78 | { | 155 | { |
79 | perror("FIFO 2 exists, but FIFO 1 not, blub"); | 156 | fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); |
80 | exit(1); | 157 | exit(1); |
81 | } | 158 | } |
82 | first = 1; | 159 | |
83 | perror("First"); | ||
84 | umask(0); | 160 | umask(0); |
85 | erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); | 161 | //unlink(FIFO_FILE1); |
162 | //unlink(FIFO_FILE2); | ||
163 | // FIXME: use mkfifo! | ||
164 | erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); | ||
165 | if (0 != erg) | ||
166 | { | ||
167 | fprintf(stderr, "Error at mknode1 \n"); | ||
168 | //exit(1); | ||
169 | } | ||
86 | erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0); | 170 | erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0); |
171 | if (0 != erg) | ||
172 | { | ||
173 | fprintf(stderr, "Error at mknode2 \n"); | ||
174 | //exit(1); | ||
175 | } | ||
87 | 176 | ||
88 | if ((fpin = fopen(FIFO_FILE1, "r")) == NULL) | 177 | } |
178 | else | ||
179 | { | ||
180 | |||
181 | if (0 != stat(FIFO_FILE2, &st)) | ||
89 | { | 182 | { |
90 | perror("fopen"); | 183 | fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); |
91 | exit(1); | 184 | exit(1); |
92 | } | 185 | } |
93 | if ((fpout = fopen(FIFO_FILE2, "w")) == NULL) | 186 | |
187 | } | ||
188 | |||
189 | if (strstr(argv[1], "1")) | ||
190 | { | ||
191 | //fprintf(stderr, "First\n"); | ||
192 | first = 1; | ||
193 | fpin = fopen(FIFO_FILE1, "r"); | ||
194 | if (NULL == fpin) | ||
195 | { | ||
196 | fprintf(stderr, "fopen of read FIFO_FILE1\n"); | ||
197 | goto end; | ||
198 | } | ||
199 | fpout = fopen(FIFO_FILE2, "w"); | ||
200 | if (NULL == fpout) | ||
94 | { | 201 | { |
95 | perror("fopen"); | 202 | fprintf(stderr, "fopen of write FIFO_FILE2\n"); |
96 | exit(1); | 203 | goto end; |
97 | } | 204 | } |
205 | |||
98 | } | 206 | } |
99 | else | 207 | else |
100 | { | 208 | { |
101 | first = 0; | 209 | first = 0; |
102 | perror("Second"); | 210 | //fprintf(stderr, "Second\n"); |
103 | if (stat(FIFO_FILE2, &st2) != 0) | 211 | fpout = fopen(FIFO_FILE1, "w"); |
212 | if (NULL == fpout) | ||
104 | { | 213 | { |
105 | perror("FIFO 1 exists, but FIFO 2 not, mäh"); | 214 | fprintf(stderr, "fopen of write FIFO_FILE1\n"); |
106 | exit(1); | 215 | goto end; |
107 | } | 216 | } |
108 | if ((fpout = fopen(FIFO_FILE1, "w")) == NULL) | 217 | fpin = fopen(FIFO_FILE2, "r"); |
218 | if (NULL == fpin) | ||
109 | { | 219 | { |
110 | perror("fopen"); | 220 | fprintf(stderr, "fopen of read FIFO_FILE2\n"); |
111 | exit(1); | 221 | goto end; |
112 | } | ||
113 | if ((fpin = fopen(FIFO_FILE2, "r")) == NULL) | ||
114 | { | ||
115 | perror("fopen"); | ||
116 | exit(1); | ||
117 | } | 222 | } |
118 | 223 | ||
119 | } | 224 | } |
120 | 225 | ||
121 | // fork | 226 | fdpin = fileno(fpin); |
227 | GNUNET_assert(fpin >= 0); | ||
122 | 228 | ||
123 | if ((pid = fork()) < 0) | 229 | if (fdpin >= FD_SETSIZE) |
124 | { | 230 | { |
125 | perror("FORK ERROR"); | 231 | fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin, |
126 | 232 | (unsigned int) FD_SETSIZE); | |
127 | //clean up | 233 | goto end; |
128 | if (first == 1) | ||
129 | { | ||
130 | unlink(FIFO_FILE1); | ||
131 | unlink(FIFO_FILE2); | ||
132 | } | ||
133 | fclose(fpin); | ||
134 | fclose(fpout); | ||
135 | return -3; | ||
136 | } | 234 | } |
137 | else if (pid == 0) // CHILD PROCESS | 235 | |
236 | fdpout = fileno(fpout); | ||
237 | GNUNET_assert(fdpout >= 0 ); | ||
238 | |||
239 | if (fdpout >= FD_SETSIZE) | ||
138 | { | 240 | { |
139 | perror("Child"); | 241 | fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout, |
140 | signal(SIGINT, sigfunc); | 242 | (unsigned int) FD_SETSIZE); |
141 | signal(SIGTERM, sigfunc); | 243 | goto end; |
142 | signal(SIGKILL, sigfunc); | ||
143 | int rv = 0; | ||
144 | int readc = 0; | ||
145 | int pos = 0; | ||
146 | char line[MAXLINE]; | ||
147 | 244 | ||
148 | fd_set rfds; | 245 | } |
149 | fd_set wfds; | ||
150 | struct timeval tv; | ||
151 | int retval; | ||
152 | 246 | ||
247 | signal(SIGINT, &sigfunc); | ||
248 | signal(SIGTERM, &sigfunc); | ||
153 | 249 | ||
154 | tv.tv_sec = 5; | 250 | char readbuf[MAXLINE]; |
155 | tv.tv_usec = 0; | 251 | int readsize = 0; |
252 | struct sendbuf write_std; | ||
253 | write_std.size = 0; | ||
254 | write_std.pos = 0; | ||
156 | 255 | ||
256 | struct sendbuf write_pout; | ||
257 | write_pout.size = 0; | ||
258 | write_pout.pos = 0; | ||
157 | 259 | ||
158 | FD_ZERO(&rfds); | 260 | int ret = 0; |
159 | FD_SET(STDIN_FILENO, &rfds); | 261 | int maxfd = 0; |
160 | 262 | ||
161 | FD_ZERO(&wfds); | 263 | fd_set rfds; |
162 | FD_SET(STDOUT_FILENO, &wfds); | 264 | fd_set wfds; |
265 | struct timeval tv; | ||
266 | int retval; | ||
163 | 267 | ||
164 | struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; | 268 | struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; |
165 | struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; | 269 | struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; |
166 | 270 | ||
167 | stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, NULL); | 271 | stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout); |
168 | file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, NULL); | 272 | file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std); |
169 | 273 | ||
170 | while (closeprog == 0) | 274 | //send mac first |
171 | { | ||
172 | readc = 0; | ||
173 | 275 | ||
276 | struct MacAddress macaddr; | ||
174 | 277 | ||
175 | while (readc < sizeof( struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader)){ | 278 | //Send random mac address |
176 | if ((rv = read(STDIN_FILENO, line, MAXLINE)) < 0) | 279 | macaddr.mac[0] = 0x13; |
177 | { | 280 | macaddr.mac[1] = 0x22; |
178 | perror("READ ERROR FROM STDIN"); | 281 | macaddr.mac[2] = 0x33; |
179 | } | 282 | macaddr.mac[3] = 0x44; |
180 | readc += rv; | 283 | macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); |
181 | } | 284 | macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); |
182 | 285 | ||
183 | pos = 0; | 286 | write_std.size = send_mac_to_plugin((char *) write_std.buf, macaddr.mac); |
184 | 287 | ||
185 | //fwrite(&line[pos], 1, sizeof(struct GNUNET_MessageHeader), fpout); | 288 | while (0 == closeprog) |
289 | { | ||
186 | 290 | ||
187 | //pos += sizeof(struct GNUNET_MessageHeader); | 291 | maxfd = 0; |
188 | 292 | ||
189 | //do not send radiotap header | 293 | //set timeout |
190 | pos += sizeof( struct RadiotapHeader); | 294 | tv.tv_sec = 5; |
295 | tv.tv_usec = 0; | ||
191 | 296 | ||
192 | while (pos < readc) | 297 | FD_ZERO(&rfds); |
193 | { | 298 | // if output queue is empty |
194 | pos += fwrite(&line[pos], 1, readc - pos, fpout); | 299 | if (0 == write_pout.size) |
195 | } | 300 | { |
301 | FD_SET(STDIN_FILENO, &rfds); | ||
302 | |||
303 | } | ||
304 | if (0 == write_std.size) | ||
305 | { | ||
306 | FD_SET(fdpin, &rfds); | ||
307 | maxfd = fdpin; | ||
308 | } | ||
309 | FD_ZERO(&wfds); | ||
310 | // if there is something to write | ||
311 | if (0 < write_std.size) | ||
312 | { | ||
313 | FD_SET(STDOUT_FILENO, &wfds); | ||
314 | maxfd = MAX(maxfd, STDOUT_FILENO); | ||
196 | } | 315 | } |
197 | 316 | ||
317 | if (0 < write_pout.size) | ||
318 | { | ||
319 | FD_SET(fdpout, &wfds); | ||
320 | maxfd = MAX(maxfd, fdpout); | ||
321 | } | ||
198 | 322 | ||
199 | //clean up | 323 | retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); |
200 | fclose(fpout); | 324 | |
201 | } | 325 | if (-1 == retval && EINTR == errno) |
202 | else // PARENT PROCESS | 326 | { |
203 | { | 327 | continue; |
204 | perror("Parent"); | 328 | } |
205 | signal(SIGINT, sigfunc); | 329 | if (0 > retval) |
206 | signal(SIGTERM, sigfunc); | ||
207 | signal(SIGKILL, sigfunc); | ||
208 | int rv = 0; | ||
209 | ssize_t pos = 0; | ||
210 | char line[MAXLINE]; | ||
211 | struct Wlan_Helper_Control_Message macmsg; | ||
212 | |||
213 | |||
214 | //Send random mac address | ||
215 | macmsg.mac.mac[0] = 0x13; | ||
216 | macmsg.mac.mac[1] = 0x22; | ||
217 | macmsg.mac.mac[2] = 0x33; | ||
218 | macmsg.mac.mac[3] = 0x44; | ||
219 | macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); | ||
220 | macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); | ||
221 | macmsg.hdr.size = sizeof(struct Wlan_Helper_Control_Message); | ||
222 | |||
223 | pos = 0; | ||
224 | /* | ||
225 | while (pos < sizeof(struct Wlan_Helper_Control_Message)) | ||
226 | { | 330 | { |
227 | pos += write(STDOUT_FILENO, &macmsg + pos, sizeof(struct Wlan_Helper_Control_Message) - pos); | 331 | fprintf(stderr, "select failed: %s\n", strerror(errno)); |
332 | closeprog = 1; | ||
333 | break; | ||
228 | } | 334 | } |
229 | */ | 335 | |
230 | while (closeprog == 0) | 336 | if (FD_ISSET(STDOUT_FILENO, &wfds)) |
231 | { | 337 | { |
232 | if ((rv = fread(line, 1, MAXLINE, fpin)) < 0) | 338 | ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, |
339 | write_std.size - write_std.pos); | ||
340 | |||
341 | if (0 > ret) | ||
342 | { | ||
343 | closeprog = 1; | ||
344 | fprintf(stderr, "Write ERROR to STDOUT\n"); | ||
345 | break; | ||
346 | } | ||
347 | else | ||
233 | { | 348 | { |
234 | perror("READ ERROR FROM fpin"); | 349 | write_std.pos += ret; |
350 | // check if finished | ||
351 | if (write_std.pos == write_std.size) | ||
352 | { | ||
353 | write_std.pos = 0; | ||
354 | write_std.size = 0; | ||
355 | } | ||
235 | } | 356 | } |
357 | } | ||
236 | 358 | ||
237 | pos = 0; | 359 | if (FD_ISSET(fdpout, &wfds)) |
238 | while (pos < rv) | 360 | { |
361 | ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size | ||
362 | - write_pout.pos); | ||
363 | |||
364 | if (0 > ret) | ||
365 | { | ||
366 | closeprog = 1; | ||
367 | fprintf(stderr, "Write ERROR to fdpout\n"); | ||
368 | } | ||
369 | else | ||
239 | { | 370 | { |
240 | pos += write(STDOUT_FILENO, &line[pos], rv - pos); | 371 | write_pout.pos += ret; |
372 | // check if finished | ||
373 | if (write_pout.pos == write_pout.size) | ||
374 | { | ||
375 | write_pout.pos = 0; | ||
376 | write_pout.size = 0; | ||
377 | } | ||
241 | } | 378 | } |
242 | } | 379 | } |
243 | 380 | ||
381 | if (FD_ISSET(STDIN_FILENO, &rfds)) | ||
382 | { | ||
383 | readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf)); | ||
244 | 384 | ||
245 | //clean up | 385 | if (0 > readsize) |
246 | fclose(fpin); | 386 | { |
387 | closeprog = 1; | ||
388 | fprintf(stderr, "Read ERROR to STDIN_FILENO\n"); | ||
389 | } | ||
390 | else if (0 < readsize) | ||
391 | { | ||
392 | GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize, | ||
393 | GNUNET_NO, GNUNET_NO); | ||
247 | 394 | ||
248 | if (first == 1) | 395 | } |
396 | else | ||
397 | { | ||
398 | //eof | ||
399 | closeprog = 1; | ||
400 | } | ||
401 | } | ||
402 | |||
403 | if (FD_ISSET(fdpin, &rfds)) | ||
249 | { | 404 | { |
250 | unlink(FIFO_FILE1); | 405 | readsize = read(fdpin, readbuf, sizeof(readbuf)); |
251 | unlink(FIFO_FILE2); | 406 | |
407 | if (0 > readsize) | ||
408 | { | ||
409 | closeprog = 1; | ||
410 | fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); | ||
411 | break; | ||
412 | } | ||
413 | else if (0 < readsize) | ||
414 | { | ||
415 | GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, | ||
416 | GNUNET_NO, GNUNET_NO); | ||
417 | |||
418 | } | ||
419 | else | ||
420 | { | ||
421 | //eof | ||
422 | closeprog = 1; | ||
423 | } | ||
252 | } | 424 | } |
425 | |||
253 | } | 426 | } |
254 | 427 | ||
255 | // Write the input to the output | 428 | //clean up |
429 | |||
430 | GNUNET_SERVER_mst_destroy(stdin_mst); | ||
431 | GNUNET_SERVER_mst_destroy(file_in_mst); | ||
432 | |||
433 | end: if (fpout != NULL) | ||
434 | fclose(fpout); | ||
435 | if (fpin != NULL) | ||
436 | fclose(fpin); | ||
437 | |||
438 | if (1 == first) | ||
439 | { | ||
440 | unlink(FIFO_FILE1); | ||
441 | unlink(FIFO_FILE2); | ||
442 | } | ||
256 | 443 | ||
257 | return (0); | 444 | return (0); |
258 | } | 445 | } |
259 | 446 | ||
447 | int | ||
448 | main(int argc, char *argv[]) | ||
449 | { | ||
450 | if (2 != argc) | ||
451 | { | ||
452 | fprintf (stderr, | ||
453 | "This program must be started with the operating mode as argument.\n"); | ||
454 | fprintf (stderr, | ||
455 | "Usage: options\n" | ||
456 | "options:\n" | ||
457 | "1 = first loopback file\n" | ||
458 | "2 = second loopback file\n" | ||
459 | "\n"); | ||
460 | return 1; | ||
461 | } | ||
462 | if (strstr(argv[1], "1") || strstr(argv[1], "2")) | ||
463 | return testmode(argc, argv); | ||
464 | return 1; | ||
465 | } | ||