diff --git a/infrastructure-centred/owlps-listener/owlps-listener.h b/infrastructure-centred/owlps-listener/owlps-listener.h index 73750c8..f4d43a2 100644 --- a/infrastructure-centred/owlps-listener/owlps-listener.h +++ b/infrastructure-centred/owlps-listener/owlps-listener.h @@ -28,8 +28,8 @@ #endif // USE_PTHREAD #include -/* defines le32toh only in glibc >= 2.9. If we use an older - * version of glibc, or another libc (e.g. uClibc), we must define it +/* defines le*toh only in glibc >= 2.9. If we use an older + * version of glibc, or another libc (e.g. uClibc), we must define them * manually. */ #ifndef le32toh @@ -41,6 +41,15 @@ # endif // __BYTE_ORDER == __LITTLE_ENDIAN #endif // le32toh +#ifndef le16toh +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define le16toh(x) (x) +# else // __BYTE_ORDER == __LITTLE_ENDIAN +# include +# define le16toh(x) bswap_16(x) +# endif // __BYTE_ORDER == __LITTLE_ENDIAN +#endif // le16toh + // Used by get_mac_addr(): #include #include diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index a395576..42c8eb2 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -498,7 +498,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, // Copy 2 bytes from the 3rd data byte, that is the size of the rtap // header (changes with the flags): memcpy(&rtap_bytes, &data[2], sizeof(unsigned short)) ; - rtap_bytes = ntohs(rtap_bytes) ; + // Radiotap header is little-endian + rtap_bytes = le16toh(rtap_bytes) ; // After the rtap header, there is the 802.11 header; the first byte // is the packet type (beacon or not): @@ -654,13 +655,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, // Get rtap flags: memcpy(&rtap_presentflags, &data[RTAP_P_PRESENTFLAGS], RTAP_L_PRESENTFLAGS) ; - /* We get the flags in big-endian (net-endianess), but we work on them - * as if it was in little-endian. This allows to declare an array of 15 - * bits (instead of 32), because we work only on the least significant - * bits (and so we do not reserve space for most significant bits that - * are useless). It's kind of cheat :-) - * So, on big-endian architectures, we must inverse bits as if we had - * got flags in little-endian: */ + // Radiotap header is little-endian rtap_presentflags = le32toh(rtap_presentflags) ; for (i = 0 ; i < 15 ; i++) // Initialise present flags structure