diff options
author | Marc <marc@malloc.me> | 2022-08-20 16:10:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-20 16:10:00 +0100 |
commit | 3be534eb2b75f4c3376bf61014c7a06d719cb9e3 (patch) | |
tree | bb15b431693890c51adb13784ad8b73c8c76bfde /src | |
parent | ec21e1ee1c2c475730b4b22a9f603e4b0ae7fb84 (diff) | |
download | libwifi-3be534eb2b75f4c3376bf61014c7a06d719cb9e3.tar.gz libwifi-3be534eb2b75f4c3376bf61014c7a06d719cb9e3.tar.bz2 libwifi-3be534eb2b75f4c3376bf61014c7a06d719cb9e3.zip |
Add macOS support (#8)
Add macOS build support
Diffstat (limited to 'src')
-rw-r--r-- | src/libwifi/core/core.c | 10 | ||||
-rw-r--r-- | src/libwifi/core/misc/byteswap.h | 25 | ||||
-rw-r--r-- | src/libwifi/parse/misc/radiotap.c | 8 |
3 files changed, 39 insertions, 4 deletions
diff --git a/src/libwifi/core/core.c b/src/libwifi/core/core.c index 0340a82..863e58f 100644 --- a/src/libwifi/core/core.c +++ b/src/libwifi/core/core.c | |||
@@ -25,9 +25,17 @@ void libwifi_random_mac(unsigned char buf[6], unsigned char prefix[3]) { | |||
25 | memset(buf, 0, 6); | 25 | memset(buf, 0, 6); |
26 | if (prefix != NULL) { | 26 | if (prefix != NULL) { |
27 | memcpy(buf, prefix, 3); | 27 | memcpy(buf, prefix, 3); |
28 | getrandom(buf + 3, 3, 0); | 28 | #if __APPLE__ |
29 | arc4random_buf(buf + 3, 3); | ||
30 | #else | ||
31 | getrandom(buf + 3, 3, 0); | ||
32 | #endif /* __APPLE__ */ | ||
29 | } else { | 33 | } else { |
34 | #if __APPLE__ | ||
35 | arc4random_buf(buf, 6); | ||
36 | #else | ||
30 | getrandom(buf, 6, 0); | 37 | getrandom(buf, 6, 0); |
38 | #endif /* __APPLE__ */ | ||
31 | } | 39 | } |
32 | } | 40 | } |
33 | 41 | ||
diff --git a/src/libwifi/core/misc/byteswap.h b/src/libwifi/core/misc/byteswap.h index cab264f..aa91a37 100644 --- a/src/libwifi/core/misc/byteswap.h +++ b/src/libwifi/core/misc/byteswap.h | |||
@@ -16,6 +16,28 @@ | |||
16 | #ifndef LIBWIFI_CORE_BYTESWAP_H | 16 | #ifndef LIBWIFI_CORE_BYTESWAP_H |
17 | #define LIBWIFI_CORE_BYTESWAP_H | 17 | #define LIBWIFI_CORE_BYTESWAP_H |
18 | 18 | ||
19 | #if __APPLE__ | ||
20 | #include <libkern/OSByteOrder.h> | ||
21 | |||
22 | #define BYTESWAP16(x) OSSwapInt16(x) | ||
23 | #define BYTESWAP32(x) OSSwapInt32(x) | ||
24 | #define BYTESWAP64(x) OSSwapInt64(x) | ||
25 | |||
26 | #define htobe16(x) OSSwapHostToBigInt16(x) | ||
27 | #define htole16(x) OSSwapHostToLittleInt16(x) | ||
28 | #define be16toh(x) OSSwapBigToHostInt16(x) | ||
29 | #define le16toh(x) OSSwapLittleToHostInt16(x) | ||
30 | |||
31 | #define htobe32(x) OSSwapHostToBigInt32(x) | ||
32 | #define htole32(x) OSSwapHostToLittleInt32(x) | ||
33 | #define be32toh(x) OSSwapBigToHostInt32(x) | ||
34 | #define le32toh(x) OSSwapLittleToHostInt32(x) | ||
35 | |||
36 | #define htobe64(x) OSSwapHostToBigInt64(x) | ||
37 | #define htole64(x) OSSwapHostToLittleInt64(x) | ||
38 | #define be64toh(x) OSSwapBigToHostInt64(x) | ||
39 | #define le64toh(x) OSSwapLittleToHostInt64(x) | ||
40 | #else | ||
19 | #include <byteswap.h> | 41 | #include <byteswap.h> |
20 | 42 | ||
21 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | 43 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
@@ -26,6 +48,7 @@ | |||
26 | #define BYTESWAP16(x) (__bswap_16(x)) | 48 | #define BYTESWAP16(x) (__bswap_16(x)) |
27 | #define BYTESWAP32(x) (__bswap_32(x)) | 49 | #define BYTESWAP32(x) (__bswap_32(x)) |
28 | #define BYTESWAP64(x) (__bswap_32(x)) | 50 | #define BYTESWAP64(x) (__bswap_32(x)) |
29 | #endif | 51 | #endif /* __BYTE_ORDER__ */ |
52 | #endif /* __APPLE__ */ | ||
30 | 53 | ||
31 | #endif /* LIBWIFI_CORE_BYTESWAP_H */ | 54 | #endif /* LIBWIFI_CORE_BYTESWAP_H */ |
diff --git a/src/libwifi/parse/misc/radiotap.c b/src/libwifi/parse/misc/radiotap.c index 80ddced..faf6009 100644 --- a/src/libwifi/parse/misc/radiotap.c +++ b/src/libwifi/parse/misc/radiotap.c | |||
@@ -17,14 +17,18 @@ | |||
17 | #include "../../core/radiotap/radiotap_iter.h" | 17 | #include "../../core/radiotap/radiotap_iter.h" |
18 | 18 | ||
19 | #include <errno.h> | 19 | #include <errno.h> |
20 | #include <endian.h> | ||
21 | #include <stdint.h> | 20 | #include <stdint.h> |
22 | 21 | ||
22 | #if !(__APPLE__) | ||
23 | #include <endian.h> | ||
24 | #endif | ||
25 | |||
23 | /** | 26 | /** |
24 | * The libwifi radiotap parser uses the usual ieee80211_radiotap_iterator to parse incoming | 27 | * The libwifi radiotap parser uses the usual ieee80211_radiotap_iterator to parse incoming |
25 | * radiotap headers into a consumable libwifi_radiotap_info struct. | 28 | * radiotap headers into a consumable libwifi_radiotap_info struct. |
26 | */ | 29 | */ |
27 | int libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame, size_t frame_len) { | 30 | int libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame, |
31 | size_t frame_len) { | ||
28 | memset(info, 0, sizeof(struct libwifi_radiotap_info)); | 32 | memset(info, 0, sizeof(struct libwifi_radiotap_info)); |
29 | 33 | ||
30 | if (frame_len < sizeof(struct ieee80211_radiotap_header)) { | 34 | if (frame_len < sizeof(struct ieee80211_radiotap_header)) { |