diff options
author | ng0 <ng0@n0.is> | 2019-09-06 23:01:06 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-06 23:01:06 +0000 |
commit | d0051cb6683c712cce3473d6b667208e4f61b75a (patch) | |
tree | 99f642c0e8f8c888a2bb3daa5280325dd8707d6d /src/transport/gnunet-helper-transport-wlan-dummy.c | |
parent | 6e599264ad13e8fc105493d74d7c11d46f8739ed (diff) | |
download | gnunet-d0051cb6683c712cce3473d6b667208e4f61b75a.tar.gz gnunet-d0051cb6683c712cce3473d6b667208e4f61b75a.zip |
plibc, commit 2
Diffstat (limited to 'src/transport/gnunet-helper-transport-wlan-dummy.c')
-rw-r--r-- | src/transport/gnunet-helper-transport-wlan-dummy.c | 128 |
1 files changed, 68 insertions, 60 deletions
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c index c7ed1b903..0adf8f6a5 100644 --- a/src/transport/gnunet-helper-transport-wlan-dummy.c +++ b/src/transport/gnunet-helper-transport-wlan-dummy.c | |||
@@ -104,13 +104,14 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) | |||
104 | struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; | 104 | struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; |
105 | 105 | ||
106 | GNUNET_memcpy (&macmsg.mac, | 106 | GNUNET_memcpy (&macmsg.mac, |
107 | (char *) mac, | 107 | (char *) mac, |
108 | sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); | 108 | sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); |
109 | macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); | 109 | macmsg.hdr.size = |
110 | htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); | ||
110 | macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); | 111 | macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); |
111 | GNUNET_memcpy (buffer, | 112 | GNUNET_memcpy (buffer, |
112 | &macmsg, | 113 | &macmsg, |
113 | sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); | 114 | sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); |
114 | return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); | 115 | return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); |
115 | } | 116 | } |
116 | 117 | ||
@@ -126,8 +127,7 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) | |||
126 | * #GNUNET_SYSERR to stop further processing with error | 127 | * #GNUNET_SYSERR to stop further processing with error |
127 | */ | 128 | */ |
128 | static int | 129 | static int |
129 | stdin_send (void *cls, | 130 | stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr) |
130 | const struct GNUNET_MessageHeader *hdr) | ||
131 | { | 131 | { |
132 | struct SendBuffer *write_pout = cls; | 132 | struct SendBuffer *write_pout = cls; |
133 | const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; | 133 | const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; |
@@ -137,16 +137,19 @@ stdin_send (void *cls, | |||
137 | 137 | ||
138 | sendsize = ntohs (hdr->size); | 138 | sendsize = ntohs (hdr->size); |
139 | in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; | 139 | in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; |
140 | if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || | 140 | if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || |
141 | (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) ) | 141 | (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize)) |
142 | { | 142 | { |
143 | fprintf (stderr, "%s", "Received malformed message\n"); | 143 | fprintf (stderr, "%s", "Received malformed message\n"); |
144 | exit (1); | 144 | exit (1); |
145 | } | 145 | } |
146 | payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); | 146 | payload_size = |
147 | if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) | 147 | sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); |
148 | if ((payload_size + | ||
149 | sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + | ||
150 | write_pout->size) > MAXLINE * 2) | ||
148 | { | 151 | { |
149 | fprintf (stderr, "%s", "Packet too big for buffer\n"); | 152 | fprintf (stderr, "%s", "Packet too big for buffer\n"); |
150 | exit (1); | 153 | exit (1); |
151 | } | 154 | } |
152 | memset (&newheader, 0, sizeof (newheader)); | 155 | memset (&newheader, 0, sizeof (newheader)); |
@@ -154,12 +157,10 @@ stdin_send (void *cls, | |||
154 | newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); | 157 | newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); |
155 | newheader.frame = in->frame; | 158 | newheader.frame = in->frame; |
156 | GNUNET_memcpy (write_pout->buf + write_pout->size, | 159 | GNUNET_memcpy (write_pout->buf + write_pout->size, |
157 | &newheader, | 160 | &newheader, |
158 | sizeof (newheader)); | 161 | sizeof (newheader)); |
159 | write_pout->size += sizeof (newheader); | 162 | write_pout->size += sizeof (newheader); |
160 | GNUNET_memcpy (write_pout->buf + write_pout->size, | 163 | GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size); |
161 | &in[1], | ||
162 | payload_size); | ||
163 | write_pout->size += payload_size; | 164 | write_pout->size += payload_size; |
164 | return GNUNET_OK; | 165 | return GNUNET_OK; |
165 | } | 166 | } |
@@ -175,8 +176,7 @@ stdin_send (void *cls, | |||
175 | * #GNUNET_SYSERR to stop further processing with error | 176 | * #GNUNET_SYSERR to stop further processing with error |
176 | */ | 177 | */ |
177 | static int | 178 | static int |
178 | file_in_send (void *cls, | 179 | file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr) |
179 | const struct GNUNET_MessageHeader *hdr) | ||
180 | { | 180 | { |
181 | struct SendBuffer *write_std = cls; | 181 | struct SendBuffer *write_std = cls; |
182 | uint16_t sendsize; | 182 | uint16_t sendsize; |
@@ -224,45 +224,46 @@ main (int argc, char *argv[]) | |||
224 | struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr; | 224 | struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr; |
225 | int first; | 225 | int first; |
226 | 226 | ||
227 | if ( (2 != argc) || | 227 | if ((2 != argc) || |
228 | ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) ) | 228 | ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2")))) |
229 | { | 229 | { |
230 | fprintf (stderr, | 230 | fprintf ( |
231 | "%s", | 231 | stderr, |
232 | "This program must be started with the operating mode (1 or 2) as the only argument.\n"); | 232 | "%s", |
233 | "This program must be started with the operating mode (1 or 2) as the only argument.\n"); | ||
233 | return 1; | 234 | return 1; |
234 | } | 235 | } |
235 | 236 | ||
236 | /* make the fifos if needed */ | 237 | /* make the fifos if needed */ |
237 | umask (0); | 238 | umask (0); |
238 | if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || | 239 | if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || |
239 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) ) | 240 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2))) |
240 | { | 241 | { |
241 | fprintf (stderr, | 242 | fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1); |
242 | "Failed to create directory for file `%s'\n", | ||
243 | FIFO_FILE1); | ||
244 | return 1; | 243 | return 1; |
245 | } | 244 | } |
246 | if (0 == strcmp (argv[1], "1") ) | 245 | if (0 == strcmp (argv[1], "1")) |
247 | { | 246 | { |
248 | if (0 != stat (FIFO_FILE1, &st)) | 247 | if (0 != stat (FIFO_FILE1, &st)) |
249 | { | 248 | { |
250 | erg = mkfifo (FIFO_FILE1, 0666); | 249 | erg = mkfifo (FIFO_FILE1, 0666); |
251 | if ( (0 != erg) && (EEXIST != errno) ) | 250 | if ((0 != erg) && (EEXIST != errno)) |
252 | fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1, | 251 | fprintf (stderr, |
253 | strerror (errno)); | 252 | "Error in mkfifo(%s): %s\n", |
253 | FIFO_FILE1, | ||
254 | strerror (errno)); | ||
254 | } | 255 | } |
255 | } | 256 | } |
256 | else | 257 | else |
257 | { | 258 | { |
258 | if (0 != stat (FIFO_FILE2, &st)) | 259 | if (0 != stat (FIFO_FILE2, &st)) |
259 | { | 260 | { |
260 | GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); | 261 | GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); |
261 | if ( (0 != erg) && (EEXIST != errno) ) | 262 | if ((0 != erg) && (EEXIST != errno)) |
262 | fprintf (stderr, | 263 | fprintf (stderr, |
263 | "Error in mkfifo(%s): %s\n", | 264 | "Error in mkfifo(%s): %s\n", |
264 | FIFO_FILE2, | 265 | FIFO_FILE2, |
265 | strerror (errno)); | 266 | strerror (errno)); |
266 | } | 267 | } |
267 | } | 268 | } |
268 | 269 | ||
@@ -274,7 +275,7 @@ main (int argc, char *argv[]) | |||
274 | { | 275 | { |
275 | fprintf (stderr, | 276 | fprintf (stderr, |
276 | "fopen of read FIFO_FILE1 failed: %s\n", | 277 | "fopen of read FIFO_FILE1 failed: %s\n", |
277 | STRERROR (errno)); | 278 | strerror (errno)); |
278 | goto end; | 279 | goto end; |
279 | } | 280 | } |
280 | if (NULL == (fpout = fopen (FIFO_FILE2, "w"))) | 281 | if (NULL == (fpout = fopen (FIFO_FILE2, "w"))) |
@@ -286,7 +287,7 @@ main (int argc, char *argv[]) | |||
286 | { | 287 | { |
287 | fprintf (stderr, | 288 | fprintf (stderr, |
288 | "fopen of write FIFO_FILE2 failed: %s\n", | 289 | "fopen of write FIFO_FILE2 failed: %s\n", |
289 | STRERROR (errno)); | 290 | strerror (errno)); |
290 | goto end; | 291 | goto end; |
291 | } | 292 | } |
292 | } | 293 | } |
@@ -295,14 +296,14 @@ main (int argc, char *argv[]) | |||
295 | first = 0; | 296 | first = 0; |
296 | if (NULL == (fpout = fopen (FIFO_FILE1, "w"))) | 297 | if (NULL == (fpout = fopen (FIFO_FILE1, "w"))) |
297 | { | 298 | { |
298 | GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); | 299 | GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); |
299 | fpout = fopen (FIFO_FILE1, "w"); | 300 | fpout = fopen (FIFO_FILE1, "w"); |
300 | } | 301 | } |
301 | if (NULL == fpout) | 302 | if (NULL == fpout) |
302 | { | 303 | { |
303 | fprintf (stderr, | 304 | fprintf (stderr, |
304 | "fopen of write FIFO_FILE1 failed: %s\n", | 305 | "fopen of write FIFO_FILE1 failed: %s\n", |
305 | STRERROR (errno)); | 306 | strerror (errno)); |
306 | goto end; | 307 | goto end; |
307 | } | 308 | } |
308 | fpin = fopen (FIFO_FILE2, "r"); | 309 | fpin = fopen (FIFO_FILE2, "r"); |
@@ -310,7 +311,7 @@ main (int argc, char *argv[]) | |||
310 | { | 311 | { |
311 | fprintf (stderr, | 312 | fprintf (stderr, |
312 | "fopen of read FIFO_FILE2 failed: %s\n", | 313 | "fopen of read FIFO_FILE2 failed: %s\n", |
313 | STRERROR (errno)); | 314 | strerror (errno)); |
314 | goto end; | 315 | goto end; |
315 | } | 316 | } |
316 | } | 317 | } |
@@ -395,21 +396,22 @@ main (int argc, char *argv[]) | |||
395 | continue; | 396 | continue; |
396 | if (0 > retval) | 397 | if (0 > retval) |
397 | { | 398 | { |
398 | fprintf (stderr, "select failed: %s\n", STRERROR (errno)); | 399 | fprintf (stderr, "select failed: %s\n", strerror (errno)); |
399 | closeprog = 1; | 400 | closeprog = 1; |
400 | break; | 401 | break; |
401 | } | 402 | } |
402 | 403 | ||
403 | if (FD_ISSET (STDOUT_FILENO, &wfds)) | 404 | if (FD_ISSET (STDOUT_FILENO, &wfds)) |
404 | { | 405 | { |
405 | ret = | 406 | ret = write (STDOUT_FILENO, |
406 | write (STDOUT_FILENO, write_std.buf + write_std.pos, | 407 | write_std.buf + write_std.pos, |
407 | write_std.size - write_std.pos); | 408 | write_std.size - write_std.pos); |
408 | if (0 > ret) | 409 | if (0 > ret) |
409 | { | 410 | { |
410 | closeprog = 1; | 411 | closeprog = 1; |
411 | fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n", | 412 | fprintf (stderr, |
412 | STRERROR (errno)); | 413 | "Write ERROR to STDOUT_FILENO: %s\n", |
414 | strerror (errno)); | ||
413 | break; | 415 | break; |
414 | } | 416 | } |
415 | else | 417 | else |
@@ -426,14 +428,16 @@ main (int argc, char *argv[]) | |||
426 | 428 | ||
427 | if (FD_ISSET (fdpout, &wfds)) | 429 | if (FD_ISSET (fdpout, &wfds)) |
428 | { | 430 | { |
429 | ret = | 431 | ret = write (fdpout, |
430 | write (fdpout, write_pout.buf + write_pout.pos, | 432 | write_pout.buf + write_pout.pos, |
431 | write_pout.size - write_pout.pos); | 433 | write_pout.size - write_pout.pos); |
432 | 434 | ||
433 | if (0 > ret) | 435 | if (0 > ret) |
434 | { | 436 | { |
435 | closeprog = 1; | 437 | closeprog = 1; |
436 | fprintf (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno)); | 438 | fprintf (stderr, |
439 | "Write ERROR to fdpout failed: %s\n", | ||
440 | strerror (errno)); | ||
437 | } | 441 | } |
438 | else | 442 | else |
439 | { | 443 | { |
@@ -454,15 +458,17 @@ main (int argc, char *argv[]) | |||
454 | if (0 > readsize) | 458 | if (0 > readsize) |
455 | { | 459 | { |
456 | closeprog = 1; | 460 | closeprog = 1; |
457 | fprintf (stderr, "Error reading from STDIN_FILENO: %s\n", | 461 | fprintf (stderr, |
458 | STRERROR (errno)); | 462 | "Error reading from STDIN_FILENO: %s\n", |
463 | strerror (errno)); | ||
459 | } | 464 | } |
460 | else if (0 < readsize) | 465 | else if (0 < readsize) |
461 | { | 466 | { |
462 | GNUNET_MST_from_buffer (stdin_mst, | 467 | GNUNET_MST_from_buffer (stdin_mst, |
463 | readbuf, readsize, | 468 | readbuf, |
464 | GNUNET_NO, GNUNET_NO); | 469 | readsize, |
465 | 470 | GNUNET_NO, | |
471 | GNUNET_NO); | ||
466 | } | 472 | } |
467 | else | 473 | else |
468 | { | 474 | { |
@@ -477,14 +483,16 @@ main (int argc, char *argv[]) | |||
477 | if (0 > readsize) | 483 | if (0 > readsize) |
478 | { | 484 | { |
479 | closeprog = 1; | 485 | closeprog = 1; |
480 | fprintf (stderr, "Error reading from fdpin: %s\n", STRERROR (errno)); | 486 | fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno)); |
481 | break; | 487 | break; |
482 | } | 488 | } |
483 | else if (0 < readsize) | 489 | else if (0 < readsize) |
484 | { | 490 | { |
485 | GNUNET_MST_from_buffer (file_in_mst, | 491 | GNUNET_MST_from_buffer (file_in_mst, |
486 | readbuf, readsize, | 492 | readbuf, |
487 | GNUNET_NO, GNUNET_NO); | 493 | readsize, |
494 | GNUNET_NO, | ||
495 | GNUNET_NO); | ||
488 | } | 496 | } |
489 | else | 497 | else |
490 | { | 498 | { |