adding GNUnet endian operations
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 6 Dec 2011 14:55:46 +0000 (14:55 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 6 Dec 2011 14:55:46 +0000 (14:55 +0000)
src/include/gnunet_common.h
src/transport/gnunet-transport-wlan-helper.c
src/transport/gnunet_wlan_sender.c
src/transport/plugin_transport_wlan.c

index 7eed22fdc0f377c6a4123c515a4d07867388f97b..167187c23e1110df352c65fe6d14c5ad5e8b7a4e 100644 (file)
 
 #define GNUNET_MAX(a,b) (((a) > (b)) ? (a) : (b))
 
+/**
+ * Endian operations
+ */
+
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define GNUNET_htobe16(x) __bswap_16 (x)
+#  define GNUNET_htole16(x) (x)
+#  define GNUNET_be16toh(x) __bswap_16 (x)
+#  define GNUNET_le16toh(x) (x)
+
+#  define GNUNET_htobe32(x) __bswap_32 (x)
+#  define GNUNET_htole32(x) (x)
+#  define GNUNET_be32toh(x) __bswap_32 (x)
+#  define GNUNET_le32toh(x) (x)
+
+#  define GNUNET_htobe64(x) __bswap_64 (x)
+#  define GNUNET_htole64(x) (x)
+#  define GNUNET_be64toh(x) __bswap_64 (x)
+#  define GNUNET_le64toh(x) (x)
+# if __BYTE_ORDER == __BIG_ENDIAN
+#  define GNUNET_htobe16(x) (x)
+#  define GNUNET_htole16(x) __bswap_16 (x)
+#  define GNUNET_be16toh(x) (x)
+#  define GNUNET_le16toh(x) __bswap_16 (x)
+
+#  define GNUNET_htobe32(x) (x)
+#  define GNUNET_htole32(x) __bswap_32 (x)
+#  define GNUNET_be32toh(x) (x)
+#  define GNUNET_le32toh(x) __bswap_32 (x)
+
+#  define GNUNET_htobe64(x) (x)
+#  define GNUNET_htole64(x) __bswap_64 (x)
+#  define GNUNET_be64toh(x) (x)
+#  define GNUNET_le64toh(x) __bswap_64 (x)
+# endif
+#endif
+
+
+
 /**
  * gcc-ism to get packed structs.
  */
index ca4542f1a7f9c626f3ae3a236acafdac045ff88e..f4798c2d93c9f0ac1e0ce5934f1974f2c2aaebc6 100644 (file)
@@ -96,7 +96,6 @@
 #include <errno.h>
 #include <dirent.h>
 #include <sys/param.h>
-#include <endian.h>
 #include <unistd.h>
 #include <stdint.h>
 
@@ -399,24 +398,6 @@ struct Hardware_Infos
   (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
  /* *INDENT-ON* */
 
-#ifndef htole16
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define htole16(x) (x)
-#define le16toh(x) (x)
-#define htole32(x) (x)
-#define le32toh(x) (x)
-#define htole64(x) (x)
-#define le64toh(x) (x)
-#else
-#define htole16(x) ___my_swab16 (x)
-#define le16toh(x) ___my_swab16 (x)
-#define htole32(x) ___my_swab32 (x)
-#define le32toh(x) ___my_swab32 (x)
-#define htole64(x) ___my_swab64 (x)
-#define le64toh(x) ___my_swab64 (x)
-#endif
-#endif
-
 
 /**
  * struct ieee80211_radiotap_iterator - tracks walk through present radiotap args
@@ -494,13 +475,13 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
 
   /* sanity check for allowed length and radiotap length field */
 
-  if (max_length < (le16toh (radiotap_header->it_len)))
+  if (max_length < (GNUNET_le16toh (radiotap_header->it_len)))
     return (-EINVAL);
 
   iterator->rtheader = radiotap_header;
-  iterator->max_length = le16toh (radiotap_header->it_len);
+  iterator->max_length = GNUNET_le16toh (radiotap_header->it_len);
   iterator->arg_index = 0;
-  iterator->bitmap_shifter = le32toh (radiotap_header->it_present);
+  iterator->bitmap_shifter = GNUNET_le32toh (radiotap_header->it_present);
   iterator->arg =
       ((uint8_t *) radiotap_header) + sizeof (struct ieee80211_radiotap_header);
   iterator->this_arg = 0;
@@ -509,7 +490,7 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
 
   if ((iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
   {
-    while (le32toh (*((uint32_t *) iterator->arg)) &
+    while (GNUNET_le32toh (*((uint32_t *) iterator->arg)) &
            IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
     {
       iterator->arg += sizeof (uint32_t);
@@ -670,7 +651,7 @@ next_entry:
       {
         /* b31 was set, there is more */
         /* move to next uint32_t bitmap */
-        iterator->bitmap_shifter = le32toh (*iterator->next_bitmap);
+        iterator->bitmap_shifter = GNUNET_le32toh (*iterator->next_bitmap);
         iterator->next_bitmap++;
       }
       else
@@ -963,7 +944,7 @@ linux_read (struct Hardware_Infos *dev, unsigned char *buf, size_t buf_size,
       {
 
       case IEEE80211_RADIOTAP_TSFT:
-        ri->ri_mactime = le64toh (*((uint64_t *) iterator.this_arg));
+        ri->ri_mactime = GNUNET_le64toh (*((uint64_t *) iterator.this_arg));
         break;
 
       case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
@@ -1043,7 +1024,7 @@ linux_read (struct Hardware_Infos *dev, unsigned char *buf, size_t buf_size,
         break;
       }
     }
-    n = le16toh (rthdr->it_len);
+    n = GNUNET_le16toh (rthdr->it_len);
     if (n <= 0 || n >= caplen)
       return 0;
   }
@@ -1285,12 +1266,12 @@ stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
   struct RadioTapheader rtheader;
 
   rtheader.header.it_version = 0;
-  rtheader.header.it_len = htole16 (0x0c);
-  rtheader.header.it_present = htole32 (0x00008004);
+  rtheader.header.it_len = GNUNET_htole16 (0x0c);
+  rtheader.header.it_present = GNUNET_le16toh (0x00008004);
   rtheader.rate = 0x00;
   rtheader.pad1 = 0x00;
   rtheader.txflags =
-      htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
+      GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
 
   /*  { 0x00, 0x00, <-- radiotap version
    * 0x0c, 0x00, <- radiotap header length
@@ -1321,7 +1302,7 @@ stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
     exit (1);
   }
 
-  rtheader.header.it_len = htole16 (sizeof (rtheader));
+  rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader));
   rtheader.rate = header->rate;
   memcpy (write_pout->buf, &rtheader, sizeof (rtheader));
   memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize);
index 48151550a039b35c92a4abb04f6f76daf8cedc25..db9d744834f8ba790cdef2b0cb1782cf8ffaac82 100644 (file)
@@ -111,7 +111,7 @@ getWlanHeader (struct ieee80211_frame *Header, const char *to_mac_addr,
   memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid));
 
   tmp16 = (uint16_t *) Header->i_dur;
-  *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290);
+  *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290);
   Header->llc[0] = WLAN_LLC_DSAP_FIELD;
   Header->llc[1] = WLAN_LLC_SSAP_FIELD;
 
index bf5411d597938ab608a65590261bfc8e57a8c4ed..b5961ae38f738209359a0da5e2f87102ae32c89d 100644 (file)
@@ -1320,7 +1320,7 @@ getWlanHeader (struct ieee80211_frame *Header,
   memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
 
   tmp16 = (uint16_t *) Header->i_dur;
-  *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290);
+  *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290);
   Header->llc[0] = WLAN_LLC_DSAP_FIELD;
   Header->llc[1] = WLAN_LLC_SSAP_FIELD;