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