aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-helper-transport-wlan-dummy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-helper-transport-wlan-dummy.c')
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c595
1 files changed, 296 insertions, 299 deletions
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index 0adf8f6a5..44a54b7f6 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012 GNUnet e.V. 3 Copyright (C) 2010, 2012 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your 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 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -47,9 +47,7 @@
47/** 47/**
48 * IO buffer used for buffering data in transit. 48 * IO buffer used for buffering data in transit.
49 */ 49 */
50struct SendBuffer 50struct SendBuffer {
51{
52
53 /** 51 /**
54 * How many bytes that were stored in 'buf' did we already write to the 52 * How many bytes that were stored in 'buf' did we already write to the
55 * destination? Always smaller than 'size'. 53 * destination? Always smaller than 'size'.
@@ -82,11 +80,11 @@ static int closeprog;
82 * @param sig killing signal 80 * @param sig killing signal
83 */ 81 */
84static void 82static void
85sigfunc (int sig) 83sigfunc(int sig)
86{ 84{
87 closeprog = 1; 85 closeprog = 1;
88 (void) unlink (FIFO_FILE1); 86 (void)unlink(FIFO_FILE1);
89 (void) unlink (FIFO_FILE2); 87 (void)unlink(FIFO_FILE2);
90} 88}
91 89
92 90
@@ -98,21 +96,20 @@ sigfunc (int sig)
98 * @return number of bytes written 96 * @return number of bytes written
99 */ 97 */
100static int 98static int
101send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) 99send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
102{ 100{
103
104 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 101 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
105 102
106 GNUNET_memcpy (&macmsg.mac, 103 GNUNET_memcpy(&macmsg.mac,
107 (char *) mac, 104 (char *)mac,
108 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 105 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
109 macmsg.hdr.size = 106 macmsg.hdr.size =
110 htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 107 htons(sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
111 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 108 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
112 GNUNET_memcpy (buffer, 109 GNUNET_memcpy(buffer,
113 &macmsg, 110 &macmsg,
114 sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 111 sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
115 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); 112 return sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
116} 113}
117 114
118 115
@@ -127,7 +124,7 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
127 * #GNUNET_SYSERR to stop further processing with error 124 * #GNUNET_SYSERR to stop further processing with error
128 */ 125 */
129static int 126static int
130stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr) 127stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr)
131{ 128{
132 struct SendBuffer *write_pout = cls; 129 struct SendBuffer *write_pout = cls;
133 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; 130 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in;
@@ -135,32 +132,32 @@ stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
135 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader; 132 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader;
136 uint16_t sendsize; 133 uint16_t sendsize;
137 134
138 sendsize = ntohs (hdr->size); 135 sendsize = ntohs(hdr->size);
139 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; 136 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr;
140 if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || 137 if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)) ||
141 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize)) 138 (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize))
142 { 139 {
143 fprintf (stderr, "%s", "Received malformed message\n"); 140 fprintf(stderr, "%s", "Received malformed message\n");
144 exit (1); 141 exit(1);
145 } 142 }
146 payload_size = 143 payload_size =
147 sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); 144 sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
148 if ((payload_size + 145 if ((payload_size +
149 sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + 146 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) +
150 write_pout->size) > MAXLINE * 2) 147 write_pout->size) > MAXLINE * 2)
151 { 148 {
152 fprintf (stderr, "%s", "Packet too big for buffer\n"); 149 fprintf(stderr, "%s", "Packet too big for buffer\n");
153 exit (1); 150 exit(1);
154 } 151 }
155 memset (&newheader, 0, sizeof (newheader)); 152 memset(&newheader, 0, sizeof(newheader));
156 newheader.header.size = htons (payload_size + sizeof (newheader)); 153 newheader.header.size = htons(payload_size + sizeof(newheader));
157 newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); 154 newheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
158 newheader.frame = in->frame; 155 newheader.frame = in->frame;
159 GNUNET_memcpy (write_pout->buf + write_pout->size, 156 GNUNET_memcpy(write_pout->buf + write_pout->size,
160 &newheader, 157 &newheader,
161 sizeof (newheader)); 158 sizeof(newheader));
162 write_pout->size += sizeof (newheader); 159 write_pout->size += sizeof(newheader);
163 GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size); 160 GNUNET_memcpy(write_pout->buf + write_pout->size, &in[1], payload_size);
164 write_pout->size += payload_size; 161 write_pout->size += payload_size;
165 return GNUNET_OK; 162 return GNUNET_OK;
166} 163}
@@ -176,18 +173,18 @@ stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
176 * #GNUNET_SYSERR to stop further processing with error 173 * #GNUNET_SYSERR to stop further processing with error
177 */ 174 */
178static int 175static int
179file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr) 176file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr)
180{ 177{
181 struct SendBuffer *write_std = cls; 178 struct SendBuffer *write_std = cls;
182 uint16_t sendsize; 179 uint16_t sendsize;
183 180
184 sendsize = ntohs (hdr->size); 181 sendsize = ntohs(hdr->size);
185 if ((sendsize + write_std->size) > MAXLINE * 2) 182 if ((sendsize + write_std->size) > MAXLINE * 2)
186 { 183 {
187 fprintf (stderr, "%s", "Packet too big for buffer\n"); 184 fprintf(stderr, "%s", "Packet too big for buffer\n");
188 exit (1); 185 exit(1);
189 } 186 }
190 GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize); 187 GNUNET_memcpy(write_std->buf + write_std->size, hdr, sendsize);
191 write_std->size += sendsize; 188 write_std->size += sendsize;
192 return GNUNET_OK; 189 return GNUNET_OK;
193} 190}
@@ -201,7 +198,7 @@ file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr)
201 * @return 1 on error, 0 if terminated normally via signal 198 * @return 1 on error, 0 if terminated normally via signal
202 */ 199 */
203int 200int
204main (int argc, char *argv[]) 201main(int argc, char *argv[])
205{ 202{
206 struct stat st; 203 struct stat st;
207 int erg; 204 int erg;
@@ -225,298 +222,298 @@ main (int argc, char *argv[])
225 int first; 222 int first;
226 223
227 if ((2 != argc) || 224 if ((2 != argc) ||
228 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2")))) 225 ((0 != strcmp(argv[1], "1")) && (0 != strcmp(argv[1], "2"))))
229 {
230 fprintf (
231 stderr,
232 "%s",
233 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
234 return 1;
235 }
236
237 /* make the fifos if needed */
238 umask (0);
239 if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
240 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)))
241 {
242 fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
243 return 1;
244 }
245 if (0 == strcmp (argv[1], "1"))
246 {
247 if (0 != stat (FIFO_FILE1, &st))
248 { 226 {
249 erg = mkfifo (FIFO_FILE1, 0666); 227 fprintf(
250 if ((0 != erg) && (EEXIST != errno)) 228 stderr,
251 fprintf (stderr, 229 "%s",
252 "Error in mkfifo(%s): %s\n", 230 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
253 FIFO_FILE1, 231 return 1;
254 strerror (errno));
255 } 232 }
256 } 233
257 else 234 /* make the fifos if needed */
258 { 235 umask(0);
259 if (0 != stat (FIFO_FILE2, &st)) 236 if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE1)) ||
237 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE2)))
260 { 238 {
261 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); 239 fprintf(stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
262 if ((0 != erg) && (EEXIST != errno)) 240 return 1;
263 fprintf (stderr,
264 "Error in mkfifo(%s): %s\n",
265 FIFO_FILE2,
266 strerror (errno));
267 } 241 }
268 } 242 if (0 == strcmp(argv[1], "1"))
269
270 if (0 == strcmp (argv[1], "1"))
271 {
272 first = 1;
273 fpin = fopen (FIFO_FILE1, "r");
274 if (NULL == fpin)
275 { 243 {
276 fprintf (stderr, 244 if (0 != stat(FIFO_FILE1, &st))
277 "fopen of read FIFO_FILE1 failed: %s\n", 245 {
278 strerror (errno)); 246 erg = mkfifo(FIFO_FILE1, 0666);
279 goto end; 247 if ((0 != erg) && (EEXIST != errno))
248 fprintf(stderr,
249 "Error in mkfifo(%s): %s\n",
250 FIFO_FILE1,
251 strerror(errno));
252 }
280 } 253 }
281 if (NULL == (fpout = fopen (FIFO_FILE2, "w"))) 254 else
282 { 255 {
283 GNUNET_break (0 == mkfifo (FIFO_FILE2, 0666)); 256 if (0 != stat(FIFO_FILE2, &st))
284 fpout = fopen (FIFO_FILE2, "w"); 257 {
258 GNUNET_break(0 == (erg = mkfifo(FIFO_FILE2, 0666)));
259 if ((0 != erg) && (EEXIST != errno))
260 fprintf(stderr,
261 "Error in mkfifo(%s): %s\n",
262 FIFO_FILE2,
263 strerror(errno));
264 }
285 } 265 }
286 if (NULL == fpout) 266
267 if (0 == strcmp(argv[1], "1"))
287 { 268 {
288 fprintf (stderr, 269 first = 1;
289 "fopen of write FIFO_FILE2 failed: %s\n", 270 fpin = fopen(FIFO_FILE1, "r");
290 strerror (errno)); 271 if (NULL == fpin)
291 goto end; 272 {
273 fprintf(stderr,
274 "fopen of read FIFO_FILE1 failed: %s\n",
275 strerror(errno));
276 goto end;
277 }
278 if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
279 {
280 GNUNET_break(0 == mkfifo(FIFO_FILE2, 0666));
281 fpout = fopen(FIFO_FILE2, "w");
282 }
283 if (NULL == fpout)
284 {
285 fprintf(stderr,
286 "fopen of write FIFO_FILE2 failed: %s\n",
287 strerror(errno));
288 goto end;
289 }
292 } 290 }
293 }
294 else 291 else
295 {
296 first = 0;
297 if (NULL == (fpout = fopen (FIFO_FILE1, "w")))
298 { 292 {
299 GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); 293 first = 0;
300 fpout = fopen (FIFO_FILE1, "w"); 294 if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
295 {
296 GNUNET_break(0 == mkfifo(FIFO_FILE1, 0666));
297 fpout = fopen(FIFO_FILE1, "w");
298 }
299 if (NULL == fpout)
300 {
301 fprintf(stderr,
302 "fopen of write FIFO_FILE1 failed: %s\n",
303 strerror(errno));
304 goto end;
305 }
306 fpin = fopen(FIFO_FILE2, "r");
307 if (NULL == fpin)
308 {
309 fprintf(stderr,
310 "fopen of read FIFO_FILE2 failed: %s\n",
311 strerror(errno));
312 goto end;
313 }
301 } 314 }
302 if (NULL == fpout) 315
316 fdpin = fileno(fpin);
317 GNUNET_assert(fpin >= 0);
318 if (fdpin >= FD_SETSIZE)
303 { 319 {
304 fprintf (stderr, 320 fprintf(stderr,
305 "fopen of write FIFO_FILE1 failed: %s\n", 321 "File fdpin number too large (%d > %u)\n",
306 strerror (errno)); 322 fdpin,
323 (unsigned int)FD_SETSIZE);
307 goto end; 324 goto end;
308 } 325 }
309 fpin = fopen (FIFO_FILE2, "r"); 326
310 if (NULL == fpin) 327 fdpout = fileno(fpout);
328 GNUNET_assert(fdpout >= 0);
329
330 if (fdpout >= FD_SETSIZE)
311 { 331 {
312 fprintf (stderr, 332 fprintf(stderr,
313 "fopen of read FIFO_FILE2 failed: %s\n", 333 "File fdpout number too large (%d > %u)\n",
314 strerror (errno)); 334 fdpout,
335 (unsigned int)FD_SETSIZE);
315 goto end; 336 goto end;
316 } 337 }
317 }
318
319 fdpin = fileno (fpin);
320 GNUNET_assert (fpin >= 0);
321 if (fdpin >= FD_SETSIZE)
322 {
323 fprintf (stderr,
324 "File fdpin number too large (%d > %u)\n",
325 fdpin,
326 (unsigned int) FD_SETSIZE);
327 goto end;
328 }
329
330 fdpout = fileno (fpout);
331 GNUNET_assert (fdpout >= 0);
332 338
333 if (fdpout >= FD_SETSIZE) 339 signal(SIGINT, &sigfunc);
334 { 340 signal(SIGTERM, &sigfunc);
335 fprintf (stderr, 341 signal(GNUNET_TERM_SIG, &sigfunc);
336 "File fdpout number too large (%d > %u)\n",
337 fdpout,
338 (unsigned int) FD_SETSIZE);
339 goto end;
340 }
341
342 signal (SIGINT, &sigfunc);
343 signal (SIGTERM, &sigfunc);
344 signal (GNUNET_TERM_SIG, &sigfunc);
345 342
346 write_std.size = 0; 343 write_std.size = 0;
347 write_std.pos = 0; 344 write_std.pos = 0;
348 write_pout.size = 0; 345 write_pout.size = 0;
349 write_pout.pos = 0; 346 write_pout.pos = 0;
350 stdin_mst = GNUNET_MST_create (&stdin_send, &write_pout); 347 stdin_mst = GNUNET_MST_create(&stdin_send, &write_pout);
351 file_in_mst = GNUNET_MST_create (&file_in_send, &write_std); 348 file_in_mst = GNUNET_MST_create(&file_in_send, &write_std);
352 349
353 /* Send 'random' mac address */ 350 /* Send 'random' mac address */
354 macaddr.mac[0] = 0x13; 351 macaddr.mac[0] = 0x13;
355 macaddr.mac[1] = 0x22; 352 macaddr.mac[1] = 0x22;
356 macaddr.mac[2] = 0x33; 353 macaddr.mac[2] = 0x33;
357 macaddr.mac[3] = 0x44; 354 macaddr.mac[3] = 0x44;
358 macaddr.mac[4] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 256); 355 macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
359 macaddr.mac[5] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 256); 356 macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
360 write_std.size = send_mac_to_plugin (write_std.buf, &macaddr); 357 write_std.size = send_mac_to_plugin(write_std.buf, &macaddr);
361 358
362 while (0 == closeprog) 359 while (0 == closeprog)
363 {
364 maxfd = -1;
365 tv.tv_sec = 5;
366 tv.tv_usec = 0;
367
368 FD_ZERO (&rfds);
369 FD_ZERO (&wfds);
370 /* if output queue is empty, read */
371 if (0 == write_pout.size)
372 {
373 FD_SET (STDIN_FILENO, &rfds);
374 maxfd = MAX (STDIN_FILENO, maxfd);
375 }
376 if (0 == write_std.size)
377 { 360 {
378 FD_SET (fdpin, &rfds); 361 maxfd = -1;
379 maxfd = MAX (fdpin, maxfd); 362 tv.tv_sec = 5;
380 } 363 tv.tv_usec = 0;
364
365 FD_ZERO(&rfds);
366 FD_ZERO(&wfds);
367 /* if output queue is empty, read */
368 if (0 == write_pout.size)
369 {
370 FD_SET(STDIN_FILENO, &rfds);
371 maxfd = MAX(STDIN_FILENO, maxfd);
372 }
373 if (0 == write_std.size)
374 {
375 FD_SET(fdpin, &rfds);
376 maxfd = MAX(fdpin, maxfd);
377 }
381 378
382 /* if there is something to write, try to write */ 379 /* if there is something to write, try to write */
383 if (0 < write_std.size) 380 if (0 < write_std.size)
384 { 381 {
385 FD_SET (STDOUT_FILENO, &wfds); 382 FD_SET(STDOUT_FILENO, &wfds);
386 maxfd = MAX (maxfd, STDOUT_FILENO); 383 maxfd = MAX(maxfd, STDOUT_FILENO);
387 } 384 }
388 if (0 < write_pout.size) 385 if (0 < write_pout.size)
389 { 386 {
390 FD_SET (fdpout, &wfds); 387 FD_SET(fdpout, &wfds);
391 maxfd = MAX (maxfd, fdpout); 388 maxfd = MAX(maxfd, fdpout);
392 } 389 }
393 390
394 retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv); 391 retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
395 if ((-1 == retval) && (EINTR == errno)) 392 if ((-1 == retval) && (EINTR == errno))
396 continue; 393 continue;
397 if (0 > retval) 394 if (0 > retval)
398 { 395 {
399 fprintf (stderr, "select failed: %s\n", strerror (errno)); 396 fprintf(stderr, "select failed: %s\n", strerror(errno));
400 closeprog = 1; 397 closeprog = 1;
401 break; 398 break;
402 } 399 }
403 400
404 if (FD_ISSET (STDOUT_FILENO, &wfds)) 401 if (FD_ISSET(STDOUT_FILENO, &wfds))
405 {
406 ret = write (STDOUT_FILENO,
407 write_std.buf + write_std.pos,
408 write_std.size - write_std.pos);
409 if (0 > ret)
410 {
411 closeprog = 1;
412 fprintf (stderr,
413 "Write ERROR to STDOUT_FILENO: %s\n",
414 strerror (errno));
415 break;
416 }
417 else
418 {
419 write_std.pos += ret;
420 /* check if finished writing */
421 if (write_std.pos == write_std.size)
422 { 402 {
423 write_std.pos = 0; 403 ret = write(STDOUT_FILENO,
424 write_std.size = 0; 404 write_std.buf + write_std.pos,
405 write_std.size - write_std.pos);
406 if (0 > ret)
407 {
408 closeprog = 1;
409 fprintf(stderr,
410 "Write ERROR to STDOUT_FILENO: %s\n",
411 strerror(errno));
412 break;
413 }
414 else
415 {
416 write_std.pos += ret;
417 /* check if finished writing */
418 if (write_std.pos == write_std.size)
419 {
420 write_std.pos = 0;
421 write_std.size = 0;
422 }
423 }
425 } 424 }
426 }
427 }
428 425
429 if (FD_ISSET (fdpout, &wfds)) 426 if (FD_ISSET(fdpout, &wfds))
430 {
431 ret = write (fdpout,
432 write_pout.buf + write_pout.pos,
433 write_pout.size - write_pout.pos);
434
435 if (0 > ret)
436 {
437 closeprog = 1;
438 fprintf (stderr,
439 "Write ERROR to fdpout failed: %s\n",
440 strerror (errno));
441 }
442 else
443 {
444 write_pout.pos += ret;
445 /* check if finished writing */
446 if (write_pout.pos == write_pout.size)
447 { 427 {
448 write_pout.pos = 0; 428 ret = write(fdpout,
449 write_pout.size = 0; 429 write_pout.buf + write_pout.pos,
430 write_pout.size - write_pout.pos);
431
432 if (0 > ret)
433 {
434 closeprog = 1;
435 fprintf(stderr,
436 "Write ERROR to fdpout failed: %s\n",
437 strerror(errno));
438 }
439 else
440 {
441 write_pout.pos += ret;
442 /* check if finished writing */
443 if (write_pout.pos == write_pout.size)
444 {
445 write_pout.pos = 0;
446 write_pout.size = 0;
447 }
448 }
450 } 449 }
451 }
452 }
453 450
454 if (FD_ISSET (STDIN_FILENO, &rfds)) 451 if (FD_ISSET(STDIN_FILENO, &rfds))
455 { 452 {
456 readsize = read (STDIN_FILENO, readbuf, sizeof (readbuf)); 453 readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
457 454
458 if (0 > readsize) 455 if (0 > readsize)
459 { 456 {
460 closeprog = 1; 457 closeprog = 1;
461 fprintf (stderr, 458 fprintf(stderr,
462 "Error reading from STDIN_FILENO: %s\n", 459 "Error reading from STDIN_FILENO: %s\n",
463 strerror (errno)); 460 strerror(errno));
464 } 461 }
465 else if (0 < readsize) 462 else if (0 < readsize)
466 { 463 {
467 GNUNET_MST_from_buffer (stdin_mst, 464 GNUNET_MST_from_buffer(stdin_mst,
468 readbuf, 465 readbuf,
469 readsize, 466 readsize,
470 GNUNET_NO, 467 GNUNET_NO,
471 GNUNET_NO); 468 GNUNET_NO);
472 } 469 }
473 else 470 else
474 { 471 {
475 /* eof */ 472 /* eof */
476 closeprog = 1; 473 closeprog = 1;
477 } 474 }
478 } 475 }
479 476
480 if (FD_ISSET (fdpin, &rfds)) 477 if (FD_ISSET(fdpin, &rfds))
481 { 478 {
482 readsize = read (fdpin, readbuf, sizeof (readbuf)); 479 readsize = read(fdpin, readbuf, sizeof(readbuf));
483 if (0 > readsize) 480 if (0 > readsize)
484 { 481 {
485 closeprog = 1; 482 closeprog = 1;
486 fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno)); 483 fprintf(stderr, "Error reading from fdpin: %s\n", strerror(errno));
487 break; 484 break;
488 } 485 }
489 else if (0 < readsize) 486 else if (0 < readsize)
490 { 487 {
491 GNUNET_MST_from_buffer (file_in_mst, 488 GNUNET_MST_from_buffer(file_in_mst,
492 readbuf, 489 readbuf,
493 readsize, 490 readsize,
494 GNUNET_NO, 491 GNUNET_NO,
495 GNUNET_NO); 492 GNUNET_NO);
496 } 493 }
497 else 494 else
498 { 495 {
499 /* eof */ 496 /* eof */
500 closeprog = 1; 497 closeprog = 1;
501 } 498 }
499 }
502 } 500 }
503 }
504 501
505end: 502end:
506 /* clean up */ 503 /* clean up */
507 if (NULL != stdin_mst) 504 if (NULL != stdin_mst)
508 GNUNET_MST_destroy (stdin_mst); 505 GNUNET_MST_destroy(stdin_mst);
509 if (NULL != file_in_mst) 506 if (NULL != file_in_mst)
510 GNUNET_MST_destroy (file_in_mst); 507 GNUNET_MST_destroy(file_in_mst);
511 508
512 if (NULL != fpout) 509 if (NULL != fpout)
513 fclose (fpout); 510 fclose(fpout);
514 if (NULL != fpin) 511 if (NULL != fpin)
515 fclose (fpin); 512 fclose(fpin);
516 if (1 == first) 513 if (1 == first)
517 { 514 {
518 (void) unlink (FIFO_FILE1); 515 (void)unlink(FIFO_FILE1);
519 (void) unlink (FIFO_FILE2); 516 (void)unlink(FIFO_FILE2);
520 } 517 }
521 return 0; 518 return 0;
522} 519}