[Listener] Radiotap header is little-endian!
Use le16toh() instead of ntohs() for rtap header length.
This commit is contained in:
parent
0a8ef2793b
commit
2e16e62c44
|
@ -28,8 +28,8 @@
|
|||
#endif // USE_PTHREAD
|
||||
|
||||
#include <endian.h>
|
||||
/* <endian.h> 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
|
||||
/* <endian.h> 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 <byteswap.h>
|
||||
# define le16toh(x) bswap_16(x)
|
||||
# endif // __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#endif // le16toh
|
||||
|
||||
// Used by get_mac_addr():
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/udp.h>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue