aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-helper-transport-wlan.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-28 16:19:04 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-28 16:19:04 +0000
commit0e90e90f510428a7d3ed92add2cb4bf93595a6cf (patch)
treec24132b58679740328cc98e128602fc85f01d5c5 /src/transport/gnunet-helper-transport-wlan.c
parent2f4b20ea2c334ce412dbc1fe29253cc110765205 (diff)
downloadgnunet-0e90e90f510428a7d3ed92add2cb4bf93595a6cf.tar.gz
gnunet-0e90e90f510428a7d3ed92add2cb4bf93595a6cf.zip
-some code cleanup
Diffstat (limited to 'src/transport/gnunet-helper-transport-wlan.c')
-rw-r--r--src/transport/gnunet-helper-transport-wlan.c324
1 files changed, 177 insertions, 147 deletions
diff --git a/src/transport/gnunet-helper-transport-wlan.c b/src/transport/gnunet-helper-transport-wlan.c
index 25b94677f..582df7cf5 100644
--- a/src/transport/gnunet-helper-transport-wlan.c
+++ b/src/transport/gnunet-helper-transport-wlan.c
@@ -19,6 +19,16 @@
19 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22/**
23 * @file src/transport/gnunet-helper-transport-wlan.c
24 * @brief wlan layer two server; must run as root (SUID will do)
25 * This code will work under GNU/Linux only.
26 * @author David Brodski
27 *
28 * This program serves as the mediator between the wlan interface and
29 * gnunet
30 */
31
22/*- 32/*-
23 * we use our local copy of ieee80211_radiotap.h 33 * we use our local copy of ieee80211_radiotap.h
24 * 34 *
@@ -62,16 +72,6 @@
62 */ 72 */
63 73
64/** 74/**
65 * @file src/transport/gnunet-helper-transport-wlan.c
66 * @brief wlan layer two server; must run as root (SUID will do)
67 * This code will work under GNU/Linux only.
68 * @author David Brodski
69 *
70 * This program serves as the mediator between the wlan interface and
71 * gnunet
72 */
73
74/**
75 * parts taken from aircrack-ng, parts changend. 75 * parts taken from aircrack-ng, parts changend.
76 */ 76 */
77#define _GNU_SOURCE 77#define _GNU_SOURCE
@@ -111,8 +111,12 @@
111 */ 111 */
112#define IEEE80211_ADDR_LEN 6 112#define IEEE80211_ADDR_LEN 6
113 113
114/**
115 * Maximum size of a message allowed in either direction.
116 */
114#define MAXLINE 4096 117#define MAXLINE 4096
115 118
119
116#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000 120#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000
117 121
118 122
@@ -309,25 +313,68 @@ struct ieee80211_radiotap_header
309 uint32_t it_present; 313 uint32_t it_present;
310}; 314};
311 315
316/**
317 *
318 */
312struct RadioTapheader 319struct RadioTapheader
313{ 320{
321 /**
322 *
323 */
314 struct ieee80211_radiotap_header header; 324 struct ieee80211_radiotap_header header;
325
326 /**
327 *
328 */
315 uint8_t rate; 329 uint8_t rate;
330
331 /**
332 *
333 */
316 uint8_t pad1; 334 uint8_t pad1;
335
336 /**
337 *
338 */
317 uint16_t txflags; 339 uint16_t txflags;
318}; 340};
319 341
320 342
321/** 343/**
322 * FIXME. 344 * IO buffer used for buffering data in transit (to wireless or to stdout).
323 */ 345 */
324struct SendBuffer 346struct SendBuffer
325{ 347{
326 unsigned int pos; 348 /**
327 unsigned int size; 349 * How many bytes of data are stored in 'buf' for transmission right now?
350 * Data always starts at offset 0 and extends to 'size'.
351 */
352 size_t size;
353
354 /**
355 * How many bytes that were stored in 'buf' did we already write to the
356 * destination? Always smaller than 'size'.
357 */
358 size_t pos;
359
360 /**
361 * Buffered data; twice the maximum allowed message size as we add some
362 * headers.
363 */
328 char buf[MAXLINE * 2]; 364 char buf[MAXLINE * 2];
329}; 365};
330 366
367/**
368 * Buffer for data read from stdin to be transmitted to the wirless card.
369 */
370static struct SendBuffer write_pout;
371
372/**
373 * Buffer for data read from the wireless card to be transmitted to stdout.
374 */
375static struct SendBuffer write_std;
376
377
331GNUNET_NETWORK_STRUCT_BEGIN 378GNUNET_NETWORK_STRUCT_BEGIN
332 379
333/** 380/**
@@ -346,6 +393,7 @@ struct ieee80211_frame
346} GNUNET_PACKED; 393} GNUNET_PACKED;
347GNUNET_NETWORK_STRUCT_END 394GNUNET_NETWORK_STRUCT_END
348 395
396
349/** 397/**
350 * struct for storing the information of the hardware 398 * struct for storing the information of the hardware
351 */ 399 */
@@ -353,15 +401,14 @@ struct HardwareInfos
353{ 401{
354 402
355 /** 403 /**
356 * send buffer
357 */
358 struct SendBuffer write_pout;
359
360 /**
361 * file descriptor for the raw socket 404 * file descriptor for the raw socket
362 */ 405 */
363 int fd_raw; 406 int fd_raw;
364 407
408 /**
409 * Which format has the header that we're getting when receiving packets?
410 * Some ARPHRD_IEEE80211_XXX-value.
411 */
365 int arptype_in; 412 int arptype_in;
366 413
367 /** 414 /**
@@ -369,39 +416,16 @@ struct HardwareInfos
369 */ 416 */
370 char iface[IFNAMSIZ]; 417 char iface[IFNAMSIZ];
371 418
372 struct MacAddress pl_mac; 419 /**
420 * MAC address of our own WLAN interface.
421 */
422 struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac;
373}; 423};
374 424
375 425
376
377
378 /* *INDENT-OFF* */
379#define ___my_swab16(x) \
380((u_int16_t)( \
381 (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
382 (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
383
384#define ___my_swab32(x) \
385((u_int32_t)( \
386 (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
387 (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \
388 (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \
389 (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
390#define ___my_swab64(x) \
391((u_int64_t)( \
392 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
393 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
394 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
395 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \
396 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \
397 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
398 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
399 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
400 /* *INDENT-ON* */
401
402
403/** 426/**
404 * struct ieee80211_radiotap_iterator - tracks walk through present radiotap args 427 * struct ieee80211_radiotap_iterator - tracks walk through present radiotap arguments
428 * in the radiotap header.
405 */ 429 */
406struct ieee80211_radiotap_iterator 430struct ieee80211_radiotap_iterator
407{ 431{
@@ -922,25 +946,6 @@ next_entry:
922 946
923 947
924/** 948/**
925 * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for plugin
926 * @param buffer pointer to buffer for the message
927 * @param mac pointer to the mac address
928 * @return number of bytes written
929 */
930static int
931send_mac_to_plugin (char *buffer, struct MacAddress *mac)
932{
933 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
934
935 memcpy (&macmsg.mac, (char *) mac, sizeof (struct MacAddress));
936 macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
937 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
938 memcpy (buffer, &macmsg, sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
939 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
940}
941
942
943/**
944 * Return the channel from the frequency (in Mhz) 949 * Return the channel from the frequency (in Mhz)
945 * @param frequency of the channel 950 * @param frequency of the channel
946 * @return number of the channel 951 * @return number of the channel
@@ -960,6 +965,7 @@ get_channel_from_frequency (int frequency)
960 965
961/** 966/**
962 * function to calculate the crc, the start of the calculation 967 * function to calculate the crc, the start of the calculation
968 *
963 * @param buf buffer to calc the crc 969 * @param buf buffer to calc the crc
964 * @param len len of the buffer 970 * @param len len of the buffer
965 * @return crc sum 971 * @return crc sum
@@ -1043,10 +1049,12 @@ calc_crc_osdep (const unsigned char *buf, size_t len)
1043 1049
1044 1050
1045/** 1051/**
1046 * Function to check crc of the wlan packet 1052 * Function to calculate and check crc of the wlan packet
1047 * @param buf buffer of the packet 1053 *
1048 * @param len len of the data 1054 * @param buf buffer of the packet, with len + 4 bytes of data,
1049 * @return crc sum of the data 1055 * the last 4 bytes being the checksum
1056 * @param len length of the payload in data
1057 * @return 0 on success (checksum matches), 1 on error
1050 */ 1058 */
1051static int 1059static int
1052check_crc_buf_osdep (const unsigned char *buf, size_t len) 1060check_crc_buf_osdep (const unsigned char *buf, size_t len)
@@ -1055,15 +1063,18 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
1055 1063
1056 crc = calc_crc_osdep (buf, len); 1064 crc = calc_crc_osdep (buf, len);
1057 buf += len; 1065 buf += len;
1058 return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && 1066 if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
1059 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]); 1067 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3])
1068 return 0;
1069 return 1;
1060} 1070}
1061 1071
1062 1072
1063/** 1073/**
1064 * function to get the channel of a specific wlan card 1074 * Get the channel used by our WLAN interface.
1075 *
1065 * @param dev pointer to the dev struct of the card 1076 * @param dev pointer to the dev struct of the card
1066 * @return channel number 1077 * @return channel number, -1 on error
1067 */ 1078 */
1068static int 1079static int
1069linux_get_channel (const struct HardwareInfos *dev) 1080linux_get_channel (const struct HardwareInfos *dev)
@@ -1272,7 +1283,7 @@ linux_read (struct HardwareInfos *dev, unsigned char *buf, size_t buf_size,
1272 caplen -= n; 1283 caplen -= n;
1273 1284
1274 //detect fcs at the end, even if the flag wasn't set and remove it 1285 //detect fcs at the end, even if the flag wasn't set and remove it
1275 if ((0 == fcs_removed) && (1 == check_crc_buf_osdep (tmpbuf + n, caplen - 4))) 1286 if ((0 == fcs_removed) && (0 == check_crc_buf_osdep (tmpbuf + n, caplen - 4)))
1276 { 1287 {
1277 caplen -= 4; 1288 caplen -= 4;
1278 } 1289 }
@@ -1285,7 +1296,8 @@ linux_read (struct HardwareInfos *dev, unsigned char *buf, size_t buf_size,
1285 1296
1286 1297
1287/** 1298/**
1288 * function to open the device for read/write 1299 * Open the wireless network interface for reading/writing.
1300 *
1289 * @param dev pointer to the device struct 1301 * @param dev pointer to the device struct
1290 * @return 0 on success 1302 * @return 0 on success
1291 */ 1303 */
@@ -1398,26 +1410,19 @@ open_device_raw (struct HardwareInfos *dev)
1398 1410
1399 1411
1400/** 1412/**
1401 * function to prepare the helper, e.g. sockets, device... 1413 * Test if the given interface name really corresponds to a wireless
1402 * @param dev struct for the device 1414 * device.
1415 *
1403 * @param iface name of the interface 1416 * @param iface name of the interface
1404 * @return 0 on success 1417 * @return 0 on success, 1 on error
1405 */ 1418 */
1406static int 1419static int
1407wlan_initialize (struct HardwareInfos *dev, const char *iface) 1420test_wlan_interface (const char *iface)
1408{ 1421{
1409 char strbuf[512]; 1422 char strbuf[512];
1410 struct stat sbuf; 1423 struct stat sbuf;
1411 int ret; 1424 int ret;
1412 1425
1413 if (dev->fd_raw >= FD_SETSIZE)
1414 {
1415 fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
1416 dev->fd_raw, FD_SETSIZE);
1417 close (dev->fd_raw);
1418 return 1;
1419 }
1420
1421 /* mac80211 stack detection */ 1426 /* mac80211 stack detection */
1422 ret = 1427 ret =
1423 snprintf (strbuf, sizeof (strbuf), "/sys/class/net/%s/phy80211/subsystem", 1428 snprintf (strbuf, sizeof (strbuf), "/sys/class/net/%s/phy80211/subsystem",
@@ -1425,13 +1430,6 @@ wlan_initialize (struct HardwareInfos *dev, const char *iface)
1425 if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf))) 1430 if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf)))
1426 { 1431 {
1427 fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface); 1432 fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface);
1428 close (dev->fd_raw);
1429 return 1;
1430 }
1431 strncpy (dev->iface, iface, IFNAMSIZ);
1432 if (0 != open_device_raw (dev))
1433 {
1434 close (dev->fd_raw);
1435 return 1; 1433 return 1;
1436 } 1434 }
1437 return 0; 1435 return 0;
@@ -1484,7 +1482,6 @@ static void
1484stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) 1482stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1485{ 1483{
1486 struct HardwareInfos *dev = cls; 1484 struct HardwareInfos *dev = cls;
1487 struct SendBuffer *write_pout = &dev->write_pout;
1488 struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1]; 1485 struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1];
1489 struct ieee80211_frame *wlanheader; 1486 struct ieee80211_frame *wlanheader;
1490 size_t sendsize; 1487 size_t sendsize;
@@ -1521,56 +1518,61 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1521 1518
1522 rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader)); 1519 rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader));
1523 rtheader.rate = header->rate; 1520 rtheader.rate = header->rate;
1524 memcpy (write_pout->buf, &rtheader, sizeof (rtheader)); 1521 memcpy (write_pout.buf, &rtheader, sizeof (rtheader));
1525 memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize); 1522 memcpy (write_pout.buf + sizeof (rtheader), &header[1], sendsize);
1526 /* payload contains MAC address, but we don't trust it, so we'll 1523 /* payload contains MAC address, but we don't trust it, so we'll
1527 * overwrite it with OUR MAC address again to prevent mischief */ 1524 * overwrite it with OUR MAC address again to prevent mischief */
1528 wlanheader = (struct ieee80211_frame *) (write_pout->buf + sizeof (rtheader)); 1525 wlanheader = (struct ieee80211_frame *) (write_pout.buf + sizeof (rtheader));
1529 mac_set (wlanheader, dev); 1526 mac_set (wlanheader, dev);
1530 write_pout->size = sendsize + sizeof (rtheader); 1527 write_pout.size = sendsize + sizeof (rtheader);
1531} 1528}
1532 1529
1533 1530
1534/** 1531/**
1535 * main function of the helper 1532 * Main function of the helper. This code accesses a WLAN interface
1536 * @param argc number of arguments 1533 * in monitoring mode (layer 2) and then forwards traffic in both
1537 * @param argv arguments 1534 * directions between the WLAN interface and stdin/stdout of this
1538 * @return 0 on success, 1 on error 1535 * process. Error messages are written to stdout.
1536 *
1537 * @param argc number of arguments, must be 2
1538 * @param argv arguments only argument is the name of the interface (i.e. 'mon0')
1539 * @return 0 on success (never happens, as we don't return unless aborted), 1 on error
1539 */ 1540 */
1540int 1541int
1541main (int argc, char *argv[]) 1542main (int argc, char *argv[])
1542{ 1543{
1543 uid_t uid;
1544 struct HardwareInfos dev; 1544 struct HardwareInfos dev;
1545 char readbuf[MAXLINE]; 1545 char readbuf[MAXLINE];
1546 struct SendBuffer write_std;
1547 ssize_t ret;
1548 int maxfd; 1546 int maxfd;
1549 fd_set rfds; 1547 fd_set rfds;
1550 fd_set wfds; 1548 fd_set wfds;
1551 int retval;
1552 int stdin_open; 1549 int stdin_open;
1553 struct MessageStreamTokenizer *stdin_mst; 1550 struct MessageStreamTokenizer *stdin_mst;
1554 int raw_eno; 1551 int raw_eno;
1555 1552
1553 memset (&dev, 0, sizeof (dev));
1556 dev.fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL)); 1554 dev.fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
1557 raw_eno = errno; /* remember for later */ 1555 raw_eno = errno; /* remember for later */
1558 uid = getuid (); 1556
1559#ifdef HAVE_SETRESUID 1557 /* drop privs */
1560 if (0 != setresuid (uid, uid, uid))
1561 { 1558 {
1562 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); 1559 uid_t uid = getuid ();
1563 if (-1 != dev.fd_raw) 1560#ifdef HAVE_SETRESUID
1564 (void) close (dev.fd_raw); 1561 if (0 != setresuid (uid, uid, uid))
1565 return 1; 1562 {
1566 } 1563 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
1564 if (-1 != dev.fd_raw)
1565 (void) close (dev.fd_raw);
1566 return 1;
1567 }
1567#else 1568#else
1568 if (0 != (setuid (uid) | seteuid (uid))) 1569 if (0 != (setuid (uid) | seteuid (uid)))
1569 { 1570 {
1570 fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); 1571 fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
1571 if (-1 != dev.fd_raw) 1572 if (-1 != dev.fd_raw)
1572 (void) close (dev.fd_raw); 1573 (void) close (dev.fd_raw);
1573 return 1; 1574 return 1;
1575 }
1574 } 1576 }
1575#endif 1577#endif
1576 1578
@@ -1589,22 +1591,43 @@ main (int argc, char *argv[])
1589 fprintf (stderr, "Failed to create raw socket: %s\n", strerror (raw_eno)); 1591 fprintf (stderr, "Failed to create raw socket: %s\n", strerror (raw_eno));
1590 return 1; 1592 return 1;
1591 } 1593 }
1592 if (0 != wlan_initialize (&dev, argv[1])) 1594 if (dev.fd_raw >= FD_SETSIZE)
1595 {
1596 fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
1597 dev.fd_raw, FD_SETSIZE);
1598 (void) close (dev.fd_raw);
1593 return 1; 1599 return 1;
1594 dev.write_pout.size = 0; 1600 }
1595 dev.write_pout.pos = 0; 1601 if (0 != test_wlan_interface (argv[1]))
1596 stdin_mst = mst_create (&stdin_send_hw, &dev); 1602 {
1603 (void) close (dev.fd_raw);
1604 return 1;
1605 }
1606 strncpy (dev.iface, argv[1], IFNAMSIZ);
1607 if (0 != open_device_raw (&dev))
1608 {
1609 (void) close (dev.fd_raw);
1610 return 1;
1611 }
1597 1612
1598 /* send mac to STDOUT first */ 1613 /* send MAC address of the WLAN interface to STDOUT first */
1599 write_std.pos = 0; 1614 {
1600 write_std.size = send_mac_to_plugin ((char *) &write_std.buf, &dev.pl_mac); 1615 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
1601 stdin_open = 1; 1616
1617 macmsg.hdr.size = htons (sizeof (macmsg));
1618 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
1619 memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1620 memcpy (write_std.buf, &macmsg, sizeof (macmsg));
1621 write_std.size = sizeof (macmsg);
1622 }
1602 1623
1624 stdin_mst = mst_create (&stdin_send_hw, &dev);
1625 stdin_open = 1;
1603 while (1) 1626 while (1)
1604 { 1627 {
1605 maxfd = -1; 1628 maxfd = -1;
1606 FD_ZERO (&rfds); 1629 FD_ZERO (&rfds);
1607 if ((0 == dev.write_pout.size) && (1 == stdin_open)) 1630 if ((0 == write_pout.size) && (1 == stdin_open))
1608 { 1631 {
1609 FD_SET (STDIN_FILENO, &rfds); 1632 FD_SET (STDIN_FILENO, &rfds);
1610 maxfd = MAX (maxfd, STDIN_FILENO); 1633 maxfd = MAX (maxfd, STDIN_FILENO);
@@ -1620,22 +1643,24 @@ main (int argc, char *argv[])
1620 FD_SET (STDOUT_FILENO, &wfds); 1643 FD_SET (STDOUT_FILENO, &wfds);
1621 maxfd = MAX (maxfd, STDOUT_FILENO); 1644 maxfd = MAX (maxfd, STDOUT_FILENO);
1622 } 1645 }
1623 if (0 < dev.write_pout.size) 1646 if (0 < write_pout.size)
1624 { 1647 {
1625 FD_SET (dev.fd_raw, &wfds); 1648 FD_SET (dev.fd_raw, &wfds);
1626 maxfd = MAX (maxfd, dev.fd_raw); 1649 maxfd = MAX (maxfd, dev.fd_raw);
1627 } 1650 }
1628 retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
1629 if ((-1 == retval) && (EINTR == errno))
1630 continue;
1631 if (0 > retval)
1632 { 1651 {
1633 fprintf (stderr, "select failed: %s\n", strerror (errno)); 1652 int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
1634 break; 1653 if ((-1 == retval) && (EINTR == errno))
1654 continue;
1655 if (0 > retval)
1656 {
1657 fprintf (stderr, "select failed: %s\n", strerror (errno));
1658 break;
1659 }
1635 } 1660 }
1636 if (FD_ISSET (STDOUT_FILENO, &wfds)) 1661 if (FD_ISSET (STDOUT_FILENO, &wfds))
1637 { 1662 {
1638 ret = 1663 ssize_t ret =
1639 write (STDOUT_FILENO, write_std.buf + write_std.pos, 1664 write (STDOUT_FILENO, write_std.buf + write_std.pos,
1640 write_std.size - write_std.pos); 1665 write_std.size - write_std.pos);
1641 if (0 > ret) 1666 if (0 > ret)
@@ -1652,31 +1677,35 @@ main (int argc, char *argv[])
1652 } 1677 }
1653 if (FD_ISSET (dev.fd_raw, &wfds)) 1678 if (FD_ISSET (dev.fd_raw, &wfds))
1654 { 1679 {
1655 ret = write (dev.fd_raw, dev.write_pout.buf, dev.write_pout.size); 1680 ssize_t ret =
1681 write (dev.fd_raw, write_pout.buf + write_std.pos,
1682 write_pout.size - write_pout.pos);
1656 if (0 > ret) 1683 if (0 > ret)
1657 { 1684 {
1658 fprintf (stderr, "Failed to write to WLAN device: %s\n", 1685 fprintf (stderr, "Failed to write to WLAN device: %s\n",
1659 strerror (errno)); 1686 strerror (errno));
1660 break; 1687 break;
1661 } 1688 }
1662 dev.write_pout.pos += ret; 1689 write_pout.pos += ret;
1663 if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0)) 1690 if ((write_pout.pos != write_pout.size) && (0 != ret))
1664 { 1691 {
1665 /* we should not get partial sends with packet-oriented devices... */ 1692 /* we should not get partial sends with packet-oriented devices... */
1666 fprintf (stderr, "Write error, partial send: %u/%u\n", 1693 fprintf (stderr, "Write error, partial send: %u/%u\n",
1667 dev.write_pout.pos, dev.write_pout.size); 1694 (unsigned int) write_pout.pos,
1695 (unsigned int) write_pout.size);
1668 break; 1696 break;
1669 } 1697 }
1670 if (dev.write_pout.pos == dev.write_pout.size) 1698 if (write_pout.pos == write_pout.size)
1671 { 1699 {
1672 dev.write_pout.pos = 0; 1700 write_pout.pos = 0;
1673 dev.write_pout.size = 0; 1701 write_pout.size = 0;
1674 } 1702 }
1675 } 1703 }
1676 1704
1677 if (FD_ISSET (STDIN_FILENO, &rfds)) 1705 if (FD_ISSET (STDIN_FILENO, &rfds))
1678 { 1706 {
1679 ret = read (STDIN_FILENO, readbuf, sizeof (readbuf)); 1707 ssize_t ret =
1708 read (STDIN_FILENO, readbuf, sizeof (readbuf));
1680 if (0 > ret) 1709 if (0 > ret)
1681 { 1710 {
1682 fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno)); 1711 fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
@@ -1695,6 +1724,7 @@ main (int argc, char *argv[])
1695 struct GNUNET_MessageHeader *header; 1724 struct GNUNET_MessageHeader *header;
1696 struct Radiotap_rx *rxinfo; 1725 struct Radiotap_rx *rxinfo;
1697 struct ieee80211_frame *datastart; 1726 struct ieee80211_frame *datastart;
1727 ssize_t ret;
1698 1728
1699 header = (struct GNUNET_MessageHeader *) write_std.buf; 1729 header = (struct GNUNET_MessageHeader *) write_std.buf;
1700 rxinfo = (struct Radiotap_rx *) &header[1]; 1730 rxinfo = (struct Radiotap_rx *) &header[1];