src: for every AGPL3.0 file, add SPDX identifier.
[oweals/gnunet.git] / src / transport / gnunet-helper-transport-wlan.c
index b23f43dde368ddfa4a6711ae1be32a6aa411aeef..6cd45ead8daadaf24819e7167372b1cd02e07030 100644 (file)
@@ -1,23 +1,23 @@
 /*
    This file is part of GNUnet.
-   (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
+   Copyright (C) 2010, 2011, 2012 GNUnet e.V.
    Copyright (c) 2007, 2008, Andy Green <andy@warmcat.com>
-   Copyright (C) 2009 Thomas d'Otreppe
+   Copyright Copyright (C) 2009 Thomas d'Otreppe
 
-   GNUnet is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published
-   by the Free Software Foundation; either version 3, or (at your
-   option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
    GNUnet is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
+   Affero General Public License for more details.
+  
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-   You should have received a copy of the GNU General Public License
-   along with GNUnet; see the file COPYING.  If not, write to the
-   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 /**
  * @file src/transport/gnunet-helper-transport-wlan.c
  * parts taken from aircrack-ng, parts changend.
  */
 #include "gnunet_config.h"
+#define SOCKTYPE int
+#define FDTYPE int
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include "plugin_transport_wlan.h"
 
 /**
- * Packet format type for the messages we receive from 
+ * Packet format type for the messages we receive from
  * the kernel.  This is for Ethernet 10Mbps format (no
  * performance information included).
  */
-#define ARPHRD_ETHER        1 
+#define ARPHRD_ETHER        1
 
 
 /**
- * Packet format type for the messages we receive from 
+ * Packet format type for the messages we receive from
  * the kernel.  This is for plain messages (with no
  * performance information included).
  */
 
 
 /**
- * Packet format type for the messages we receive from 
+ * Packet format type for the messages we receive from
  * the kernel.  This is for the PRISM format.
  */
 #define ARPHRD_IEEE80211_PRISM  802
 
 /**
- * Packet format type for the messages we receive from 
+ * Packet format type for the messages we receive from
  * the kernel.  This is for messages with a
  * 'struct Ieee80211RadiotapHeader' (see below).
  */
  * Drivers appear to use a 64bit counter to hold mactime internal
  * the then fill the prism header with the lower 32 bits
  */
-#define PRISM_DID_MACTIME 0x2041 
+#define PRISM_DID_MACTIME 0x2041
 
 /**
  * Channel element
  */
-#define PRISM_DID_CHANNEL 0x3041 
+#define PRISM_DID_CHANNEL 0x3041
 
 /**
  * Signal element.  Should be the signal strength in dbm, some people
  * suggest that instead "100 - (strength in dbm)" is used (to make this
  * a positive integer).
  */
-#define PRISM_DID_SIGNAL 0x6041 
+#define PRISM_DID_SIGNAL 0x6041
 
 /**
  * Noise element
  */
-#define PRISM_DID_NOISE 0x7041 
+#define PRISM_DID_NOISE 0x7041
 
 /**
  * Rate element, in units/multiples of 500Khz
  */
-#define PRISM_DID_RATE 0x8041 
+#define PRISM_DID_RATE 0x8041
 
 
 /**
  * Value is set (supplied)
  */
-#define PRISM_STATUS_OK 0 
+#define PRISM_STATUS_OK 0
 
 /**
  * Value not supplied.
@@ -238,24 +240,24 @@ struct PrismValue
    * This has a different ID for each parameter, see
    * PRISM_DID_* constants.
    */
-  uint32_t did; 
-  
+  uint32_t did;
+
   /**
    * See PRISM_STATUS_*-constants.  Note that they are unusual: 0 = set;  1 = not set
    */
-  uint16_t status; 
-  
+  uint16_t status;
+
   /**
    * length of data (which is always a uint32_t, but presumably this can be used
    * to specify that fewer bytes are used (with values in 'len' from 0-4).  We
    * ignore this field.
    */
-  uint16_t len; 
+  uint16_t len;
 
   /**
    * The data value
    */
-  uint32_t data; 
+  uint32_t data;
 
 } __attribute__ ((packed));
 
@@ -269,11 +271,11 @@ struct PrismHeader
    * We expect this to be a PRISM_MSGCODE_*.
    */
   uint32_t msgcode;
-  
+
   /**
    * The length of the entire header.
    */
-  uint32_t msglen;     
+  uint32_t msglen;
 
   /**
    * Name of the device that captured the packet.
@@ -400,7 +402,7 @@ enum RadiotapType
    */
   IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
 
-  /** 
+  /**
    * IEEE80211_RADIOTAP_ANTENNA           uint8_t           antenna index
    *
    *      Unitless indication of the Rx/Tx antenna for this packet.
@@ -431,10 +433,10 @@ enum RadiotapType
    */
   IEEE80211_RADIOTAP_RX_FLAGS = 14,
 
-  /** 
+  /**
    * IEEE80211_RADIOTAP_TX_FLAGS          __le16       bitmap
    *
-   *     Properties of transmitted frames. See flags defined below.  
+   *     Properties of transmitted frames. See flags defined below.
    */
   IEEE80211_RADIOTAP_TX_FLAGS = 15,
 
@@ -460,7 +462,7 @@ enum RadiotapType
 };
 
 /**
- * Bitmask indicating an extension of the bitmask is used. 
+ * Bitmask indicating an extension of the bitmask is used.
  * (Mask corresponding to IEEE80211_RADIOTAP_EXT).
  */
 #define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK (1 << IEEE80211_RADIOTAP_EXT)
@@ -485,7 +487,7 @@ enum RadiotapType
  *
  * Frame was sent/received with short preamble
  */
-#define        IEEE80211_RADIOTAP_F_SHORTPRE   0x02  
+#define        IEEE80211_RADIOTAP_F_SHORTPRE   0x02
 
 /**
  * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -495,7 +497,7 @@ enum RadiotapType
  *
  * Frame was sent/received with WEP encryption
  */
-#define        IEEE80211_RADIOTAP_F_WEP        0x04 
+#define        IEEE80211_RADIOTAP_F_WEP        0x04
 
 /**
  * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -505,7 +507,7 @@ enum RadiotapType
  *
  * Frame was sent/received with fragmentation
  */
-#define        IEEE80211_RADIOTAP_F_FRAG       0x08 
+#define        IEEE80211_RADIOTAP_F_FRAG       0x08
 
 /**
  * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -515,7 +517,7 @@ enum RadiotapType
  *
  * Frame includes FCS (CRC at the end that needs to be removeD).
  */
-#define        IEEE80211_RADIOTAP_F_FCS        0x10    
+#define        IEEE80211_RADIOTAP_F_FCS        0x10
 
 /**
  * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -526,32 +528,32 @@ enum RadiotapType
  * Frame has padding between 802.11 header and payload
  * (to 32-bit boundary)
  */
-#define        IEEE80211_RADIOTAP_F_DATAPAD    0x20    
+#define        IEEE80211_RADIOTAP_F_DATAPAD    0x20
 
 
 /**
  * For IEEE80211_RADIOTAP_RX_FLAGS:
  * frame failed crc check
  */
-#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001  
+#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001
 
 /**
  * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
  * failed due to excessive retries
  */
-#define IEEE80211_RADIOTAP_F_TX_FAIL   0x0001  
+#define IEEE80211_RADIOTAP_F_TX_FAIL   0x0001
 
 /**
  * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
  * used cts 'protection'
  */
-#define IEEE80211_RADIOTAP_F_TX_CTS    0x0002  
+#define IEEE80211_RADIOTAP_F_TX_CTS    0x0002
 
 /**
  * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
- * used rts/cts handshake 
+ * used rts/cts handshake
  */
-#define IEEE80211_RADIOTAP_F_TX_RTS    0x0004  
+#define IEEE80211_RADIOTAP_F_TX_RTS    0x0004
 
 /**
  * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
@@ -561,7 +563,7 @@ enum RadiotapType
 
 /**
  * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
- * sequence number handled by userspace 
+ * sequence number handled by userspace
  */
 #define IEEE80211_RADIOTAP_F_TX_NOSEQ  0x0010
 
@@ -589,7 +591,7 @@ struct Ieee80211RadiotapHeader
   uint8_t it_version;
 
   /**
-   * Padding.  Set to 0.  
+   * Padding.  Set to 0.
    */
   uint8_t it_pad;
 
@@ -609,7 +611,7 @@ struct Ieee80211RadiotapHeader
 
 
 /**
- * Format of the header we need to prepend to messages to be sent to the 
+ * Format of the header we need to prepend to messages to be sent to the
  * Kernel.
  */
 struct RadiotapTransmissionHeader
@@ -750,7 +752,7 @@ struct SendBuffer
    * destination?  Always smaller than 'size'.
    */
   size_t pos;
-  
+
   /**
    * Buffered data; twice the maximum allowed message size as we add some
    * headers.
@@ -792,7 +794,7 @@ static struct SendBuffer write_std;
  * @param cls closure
  * @param message the actual message
  */
-typedef void (*MessageTokenizerCallback) (void *cls, 
+typedef void (*MessageTokenizerCallback) (void *cls,
                                          const struct
                                          GNUNET_MessageHeader *
                                          message);
@@ -908,7 +910,7 @@ do_align:
       delta =
           GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
                       (mst->pos - mst->off), size);
-      memcpy (&ibuf[mst->pos], buf, delta);
+      GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
       mst->pos += delta;
       buf += delta;
       size -= delta;
@@ -947,7 +949,7 @@ do_align:
     if (mst->pos - mst->off < want)
     {
       delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
-      memcpy (&ibuf[mst->pos], buf, delta);
+      GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
       mst->pos += delta;
       buf += delta;
       size -= delta;
@@ -1014,7 +1016,7 @@ do_align:
               "Assertion failed\n");
       exit (1);
     }
-    memcpy (&ibuf[mst->pos], buf, size);
+    GNUNET_memcpy (&ibuf[mst->pos], buf, size);
     mst->pos += size;
   }
   return ret;
@@ -1057,7 +1059,7 @@ mst_destroy (struct MessageStreamTokenizer *mst)
  */
 static int
 ieee80211_radiotap_iterator_init (struct Ieee80211RadiotapHeaderIterator *iterator,
-                                  const struct Ieee80211RadiotapHeader *radiotap_header, 
+                                  const struct Ieee80211RadiotapHeader *radiotap_header,
                                  size_t max_length)
 {
   if ( (iterator == NULL) ||
@@ -1202,26 +1204,26 @@ ieee80211_radiotap_iterator_next (struct Ieee80211RadiotapHeaderIterator *iterat
        /* need padding (by 'wanted_alignment - unalignment') */
        iterator->arg_index += wanted_alignment - unalignment;
       }
-      
+
       /*
        * this is what we will return to user, but we need to
        * move on first so next call has something fresh to test
-       */     
+       */
       iterator->this_arg_index = iterator->arg_index;
       iterator->this_arg = iterator->arg;
 
       /* internally move on the size of this arg (using lower nybble from
-        the table) */ 
+        the table) */
       iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
-      
+
       /*
        * check for insanity where we are given a bitmap that
        * claims to have more arg content than the length of the
        * radiotap section.  We will normally end up equalling this
        * max_length on the last arg, never exceeding it.
-       */      
+       */
       if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > iterator->max_length)
-       return -1;      
+       return -1;
     }
 
     /* Now, move on to next bit / next entry */
@@ -1243,7 +1245,7 @@ ieee80211_radiotap_iterator_next (struct Ieee80211RadiotapHeaderIterator *iterat
       }
     }
     else
-    {                           
+    {
       /* just try the next bit (while loop will move on) */
       iterator->bitmap_shifter >>= 1;
     }
@@ -1362,7 +1364,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
   if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
       ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3])
     return 0;
-  return 1;     
+  return 1;
 }
 
 
@@ -1429,7 +1431,7 @@ linux_get_channel (const struct HardwareInfos *dev)
  * @return number of bytes written to 'buf'
  */
 static ssize_t
-linux_read (struct HardwareInfos *dev, 
+linux_read (struct HardwareInfos *dev,
            unsigned char *buf, size_t buf_size,
             struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
 {
@@ -1450,7 +1452,7 @@ linux_read (struct HardwareInfos *dev,
     return -1;
   }
 
-  memset (ri, 0, sizeof (*ri)); 
+  memset (ri, 0, sizeof (*ri));
   switch (dev->arptype_in)
   {
   case ARPHRD_IEEE80211_PRISM:
@@ -1473,7 +1475,7 @@ linux_read (struct HardwareInfos *dev,
        while (left > sizeof (struct PrismValue))
        {
          left -= sizeof (struct PrismValue);
-         memcpy (&pv, pos, sizeof (struct PrismValue));
+         GNUNET_memcpy (&pv, pos, sizeof (struct PrismValue));
          pos += sizeof (struct PrismValue);
 
          switch (pv.did)
@@ -1509,7 +1511,7 @@ linux_read (struct HardwareInfos *dev,
            break;
          }
        }
-      } 
+      }
       if ( (n < 8) || (n >= caplen) )
        return 0; /* invalid format */
     }
@@ -1538,7 +1540,7 @@ linux_read (struct HardwareInfos *dev,
          if (!got_signal)
          {
            ri->ri_power = * ((int8_t*) iterator.this_arg);
-           got_signal = 1;       
+           got_signal = 1;     
          }
          break;
        case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
@@ -1592,7 +1594,7 @@ linux_read (struct HardwareInfos *dev,
          break;
        } /* end of 'switch' */
       } /* end of the 'while' loop */
-    }       
+    }
     break;
   case ARPHRD_IEEE80211:
     n = 0; /* no header */
@@ -1601,11 +1603,11 @@ linux_read (struct HardwareInfos *dev,
     {
       if (sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) > caplen)
        return 0; /* invalid */
-      memcpy (&buf[sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)],
+      GNUNET_memcpy (&buf[sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)],
              tmpbuf + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame),
              caplen - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4 /* 4 byte FCS */);
       return caplen - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4;
-    }      
+    }  
   default:
     errno = ENOTSUP; /* unsupported format */
     return -1;
@@ -1615,8 +1617,8 @@ linux_read (struct HardwareInfos *dev,
     ri->ri_channel = linux_get_channel (dev);
 
   /* detect CRC32 at the end, even if the flag wasn't set and remove it */
-  if ( (0 == fcs_removed) && 
-       (0 == check_crc_buf_osdep (tmpbuf + n, caplen - sizeof (uint32_t))) )  
+  if ( (0 == fcs_removed) &&
+       (0 == check_crc_buf_osdep (tmpbuf + n, caplen - sizeof (uint32_t))) )
   {
     /* NOTE: this heuristic can of course fail if there happens to
        be a matching checksum at the end. Would be good to have
@@ -1624,7 +1626,7 @@ linux_read (struct HardwareInfos *dev,
     caplen -= sizeof (uint32_t);
   }
   /* copy payload to target buffer */
-  memcpy (buf, tmpbuf + n, caplen);
+  GNUNET_memcpy (buf, tmpbuf + n, caplen);
   return caplen;
 }
 
@@ -1729,7 +1731,7 @@ open_device_raw (struct HardwareInfos *dev)
     return 1;
   }
 
-  memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
+  GNUNET_memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
   dev->arptype_in = ifr.ifr_hwaddr.sa_family;
   if ((ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
       (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
@@ -1749,9 +1751,9 @@ open_device_raw (struct HardwareInfos *dev)
       setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
                   sizeof (mr)))
   {
-    fprintf (stderr, 
+    fprintf (stderr,
             "Failed to enable promiscuous mode on interface `%.*s'\n",
-             IFNAMSIZ, 
+             IFNAMSIZ,
             dev->iface);
     return 1;
   }
@@ -1773,13 +1775,13 @@ test_wlan_interface (const char *iface)
   struct stat sbuf;
   int ret;
 
-  ret = snprintf (strbuf, sizeof (strbuf), 
+  ret = snprintf (strbuf, sizeof (strbuf),
                  "/sys/class/net/%s/phy80211/subsystem",
                  iface);
   if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf)))
   {
-    fprintf (stderr, 
-            "Did not find 802.11 interface `%s'. Exiting.\n", 
+    fprintf (stderr,
+            "Did not find 802.11 interface `%s'. Exiting.\n",
             iface);
     exit (1);
   }
@@ -1850,7 +1852,7 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
   sendsize = ntohs (hdr->size);
   if ( (sendsize <
        sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
-       (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ) 
+       (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) )
   {
     fprintf (stderr, "Received malformed message\n");
     exit (1);
@@ -1868,14 +1870,14 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
   case ARPHRD_IEEE80211_FULL:
   case ARPHRD_IEEE80211:
     rtheader.header.it_version = 0;
-    rtheader.header.it_pad = 0; 
+    rtheader.header.it_pad = 0;
     rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader));
     rtheader.header.it_present = GNUNET_htole16 (IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK);
-    rtheader.rate = header->rate; 
+    rtheader.rate = header->rate;
     rtheader.pad1 = 0;
     rtheader.txflags = GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
-    memcpy (write_pout.buf, &rtheader, sizeof (rtheader));
-    memcpy (&write_pout.buf[sizeof (rtheader)], &header->frame, sendsize);
+    GNUNET_memcpy (write_pout.buf, &rtheader, sizeof (rtheader));
+    GNUNET_memcpy (&write_pout.buf[sizeof (rtheader)], &header->frame, sendsize);
     wlanheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf[sizeof (rtheader)];
 
     /* payload contains MAC address, but we don't trust it, so we'll
@@ -1888,8 +1890,8 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
     /* etheader.src = header->frame.addr2; --- untrusted input */
     etheader.src = dev->pl_mac;
     etheader.type = htons (ETH_P_IP);
-    memcpy (write_pout.buf, &etheader, sizeof (etheader));
-    memcpy (&write_pout.buf[sizeof (etheader)], &header[1], sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
+    GNUNET_memcpy (write_pout.buf, &etheader, sizeof (etheader));
+    GNUNET_memcpy (&write_pout.buf[sizeof (etheader)], &header[1], sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
     write_pout.size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + sizeof (etheader);
     break;
   default:
@@ -1921,23 +1923,28 @@ main (int argc, char *argv[])
   int stdin_open;
   struct MessageStreamTokenizer *stdin_mst;
   int raw_eno;
-  uid_t uid;
 
   /* assert privs so we can modify the firewall rules! */
-  uid = getuid ();
-#ifdef HAVE_SETRESUID
-  if (0 != setresuid (uid, 0, 0))
   {
-    fprintf (stderr, "Failed to setresuid to root: %s\n", strerror (errno));
-    return 254;
-  }
+#ifdef HAVE_SETRESUID
+    uid_t uid = getuid ();
+
+    if (0 != setresuid (uid, 0, 0))
+    {
+      fprintf (stderr,
+              "Failed to setresuid to root: %s\n", 
+              strerror (errno));
+      return 254;
+    }
 #else
-  if (0 != seteuid (0)) 
-  {
-    fprintf (stderr, "Failed to seteuid back to root: %s\n", strerror (errno));
-    return 254;
-  }
+    if (0 != seteuid (0))
+    {
+      fprintf (stderr, 
+              "Failed to seteuid back to root: %s\n", strerror (errno));
+      return 254;
+    }
 #endif
+  }
 
   /* make use of SGID capabilities on POSIX */
   memset (&dev, 0, sizeof (dev));
@@ -2007,12 +2014,12 @@ main (int argc, char *argv[])
 
     macmsg.hdr.size = htons (sizeof (macmsg));
     macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
-    memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
-    memcpy (write_std.buf, &macmsg, sizeof (macmsg));
+    GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
+    GNUNET_memcpy (write_std.buf, &macmsg, sizeof (macmsg));
     write_std.size = sizeof (macmsg);
-  }  
+  }
 
-  stdin_mst = mst_create (&stdin_send_hw, &dev);  
+  stdin_mst = mst_create (&stdin_send_hw, &dev);
   stdin_open = 1;
   while (1)
   {
@@ -2069,7 +2076,7 @@ main (int argc, char *argv[])
     if (FD_ISSET (dev.fd_raw, &wfds))
     {
       ssize_t ret =
-       write (dev.fd_raw, write_pout.buf + write_std.pos, 
+       write (dev.fd_raw, write_pout.buf + write_pout.pos,
               write_pout.size - write_pout.pos);
       if (0 > ret)
       {
@@ -2095,7 +2102,7 @@ main (int argc, char *argv[])
 
     if (FD_ISSET (STDIN_FILENO, &rfds))
     {
-      ssize_t ret = 
+      ssize_t ret =
        read (STDIN_FILENO, readbuf, sizeof (readbuf));
       if (0 > ret)
       {
@@ -2118,9 +2125,9 @@ main (int argc, char *argv[])
       rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
       ret =
           linux_read (&dev, (unsigned char *) &rrm->frame,
-                      sizeof (write_std.buf) 
-                     - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) 
-                     + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), 
+                      sizeof (write_std.buf)
+                     - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+                     + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
                      rrm);
       if (0 > ret)
       {
@@ -2129,8 +2136,8 @@ main (int argc, char *argv[])
       }
       if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
       {
-        write_std.size = ret 
-         + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) 
+        write_std.size = ret
+         + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
          - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
         rrm->header.size = htons (write_std.size);
         rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);