libuwifi icon indicating copy to clipboard operation
libuwifi copied to clipboard

7031a29 fails to build on OS X 10.11.6

Open aaaaalbert opened this issue 8 years ago • 3 comments

7031a29f1ee6dc58b75a13cd4d9f20b4343904b5 kind of expectedly causes a few build errors on OS X, particularly multiple errors like these:

./linux/platform.h:11:2: error: "platform is not Linux"
./linux/platform.h:15:10: fatal error: 'endian.h' file not found

Assuming that the #errors about the platform not being Linux are only informative (which is likely a bad idea), we could just remove them (also a bad idea). endian.h on the other hand lives in a different directory on OS X, still easy to fix. This leaves us with

--- a/linux/platform.h
+++ b/linux/platform.h
@@ -7,12 +7,13 @@
  * Version 3. See the file COPYING for more details.
  */

-#ifndef __linux__
-#error "platform is not Linux"
-#endif
-
 #include <stdint.h>
+
+#ifndef __MACH__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif

 // directly included:
 //#include <stdbool.h> // bool

and

--- a/linux/inject_rtap.c
+++ b/linux/inject_rtap.c
@@ -1,5 +1,11 @@
 #include <stdint.h>
+
+#ifndef __MACH__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
+
 #include <radiotap.h>

 #include "inject.h"

radiotap (while submodule'd in) also needs this patch:

--- a/platform.h
+++ b/platform.h
@@ -3,7 +3,12 @@
 #ifndef _BSD_SOURCE
 #define _BSD_SOURCE
 #endif
+
+#ifndef __MACH__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif

 #define le16_to_cpu            le16toh
 #define le32_to_cpu            le32toh

Starting from here, things get more interesting, and probably indicate that cross-platform and platform-specific things should be broken out, and dependencies pointed out in the build instructions. Dump:

$ make
gcc -MM -I. -I./core -I./util -I./linux -I./radiotap core/channel.c core/inject.c core/node.c core/wlan_parser.c core/wlan_util.c util/average.c util/util.c linux/inject_rtap.c linux/interface.c linux/netdev.c linux/netl80211.c linux/packet_sock.c linux/platform.c linux/raw_parser.c linux/wpa_ctrl.c radiotap/radiotap.c linux/ifctrl-nl80211.c >.objdeps.mk
linux/netl80211.c:20:10: fatal error: 'netlink/attr.h' file not found
#include <netlink/attr.h>
         ^
1 error generated.
linux/packet_sock.c:16:10: fatal error: 'netpacket/packet.h' file not found
#include <netpacket/packet.h>
         ^
1 error generated.
linux/ifctrl-nl80211.c:19:10: fatal error: 'netlink/attr.h' file not found
#include <netlink/attr.h>
         ^
1 error generated.
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
echo '-std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC ' | cmp -s - .buildflags || echo '-std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC ' > .buildflags
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o core/channel.o core/channel.c
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o core/inject.o core/inject.c
core/inject.c:26:15: warning: implicit declaration of function 'htole16' is
      invalid in C99 [-Wimplicit-function-declaration]
        header->fc = htole16(probe_response ? WLAN_FRAME_PROBE_RESP : WL...
                     ^
core/inject.c:37:13: warning: implicit declaration of function 'htole64' is
      invalid in C99 [-Wimplicit-function-declaration]
        bcn->tsf = htole64(tsf);
                   ^
2 warnings generated.
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o core/node.o core/node.c
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o core/wlan_parser.o core/wlan_parser.c
core/wlan_parser.c:115:7: warning: implicit declaration of function 'le16toh' is
      invalid in C99 [-Wimplicit-function-declaration]
        fc = le16toh(wh->fc);
             ^
core/wlan_parser.c:269:18: warning: implicit declaration of function 'le64toh'
      is invalid in C99 [-Wimplicit-function-declaration]
                        p->wlan_tsf = le64toh(bc->tsf);
                                      ^
2 warnings generated.
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o core/wlan_util.o core/wlan_util.c
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o util/average.o util/average.c
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o util/util.o util/util.c
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o linux/inject_rtap.o linux/inject_rtap.c
linux/inject_rtap.c:59:20: warning: implicit declaration of function 'htole16'
      is invalid in C99 [-Wimplicit-function-declaration]
        rtaphdr->it_len = htole16(sizeof(struct inject_radiotap_header));
                          ^
linux/inject_rtap.c:60:24: warning: implicit declaration of function 'htole32'
      is invalid in C99 [-Wimplicit-function-declaration]
        rtaphdr->it_present = htole32(INJECT_RTAP_PRESENT);
                              ^
2 warnings generated.
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o linux/interface.o linux/interface.c
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./linux -I./radiotap -DDEBUG=0 -fPIC    -c -o linux/netdev.o linux/netdev.c
linux/netdev.c:33:16: error: use of undeclared identifier 'SIOCGIFHWADDR'
        if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
                      ^
linux/netdev.c:40:32: error: no member named 'ifr_hwaddr' in 'struct ifreq'
        DBG_PRINT("ARPTYPE %d\n", ifr.ifr_hwaddr.sa_family);
                                  ~~~ ^
./util/util.h:81:60: note: expanded from macro 'DBG_PRINT'
#define DBG_PRINT(...) do { if (DEBUG) printlog(LOG_DEBUG, __VA_ARGS__); } whil...
                                                           ^~~~~~~~~~~
linux/netdev.c:41:13: error: no member named 'ifr_hwaddr' in 'struct ifreq'
        return ifr.ifr_hwaddr.sa_family;
               ~~~ ^
linux/netdev.c:54:16: error: use of undeclared identifier 'SIOCGIFHWADDR'
        if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
                      ^
linux/netdev.c:61:18: error: no member named 'ifr_hwaddr' in 'struct ifreq'
        memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
                    ~~~ ^
/usr/include/secure/_string.h:65:33: note: expanded from macro 'memcpy'
  __builtin___memcpy_chk (dest, src, len, __darwin_obsz0 (dest))
                                ^~~
5 errors generated.
make: *** [linux/netdev.o] Error 1

aaaaalbert avatar Sep 22 '16 16:09 aaaaalbert

Hi, OSX should not use linux/platform.h but define it's own osx/platform.h and platform.mk

Some things in linux/ are needed though and should either be included and compiled from osx/platform.mk or moved to another subdirectory (posix/? unix/?).

The netlink stuff is not available on OSX and replaced partly in ifctrl-osx.m

Please contact me by email so we can discuss this

br101 avatar Sep 22 '16 21:09 br101

TIL setting the appropriate PLATFORM build flag helps a lot! Sorry for missing this initially. New output:

$ make PLATFORM=osx
echo '-std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./osx -DDEBUG=0 -fPIC' | cmp -s - .buildflags || echo '-std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./osx -DDEBUG=0 -fPIC' > .buildflags
cc -std=gnu99 -Wall -Wextra -I. -I./core -I./util -I./osx -DDEBUG=0 -fPIC   -c -o core/channel.o core/channel.c
In file included from core/channel.c:12:
./core/ifctrl.h:64:75: error: unknown type name 'size_t'
  ...char *const ifname, struct sta_info* inf, size_t maxlen);
                                               ^
core/channel.c:22:47: warning: implicit declaration of function 'plat_time_usec'
      is invalid in C99 [-Wimplicit-function-declaration]
        int64_t ret = (int64_t)intf->channel_time - (plat_time_usec() - ...
                                                     ^
core/channel.c:88:4: warning: implicit declaration of function 'printlog' is
      invalid in C99 [-Wimplicit-function-declaration]
                        printlog(LOG_ERR, "VHT80+80 not supported");
                        ^
core/channel.c:242:2: warning: implicitly declaring library function 'sprintf'
      with type 'int (char *, const char *, ...)'
      [-Wimplicit-function-declaration]
        sprintf(buf, "%-3d: %d HT40%s%s", c->chan, c->freq,
        ^
core/channel.c:242:2: note: include the header <stdio.h> or explicitly provide a
      declaration for 'sprintf'
3 warnings and 1 error generated.
make: *** [core/channel.o] Error 1

Post mortem:

  • Getting size_t should be a matter of including types.h.
  • plat_time_usec from linux/platform.c will need the treatment applied in br101/horst@7e51f1670b8e21eddcca0b3d4e76bfa089f3c23e for clock_gettime.
  • No idea about printlog yet. I guess this should come from linux/platform.h.
  • For sprintf, include stdio.h.

aaaaalbert avatar Oct 06 '16 11:10 aaaaalbert

For most of this, look at linux/platform.h and adapt as necessary. printlog should be provided by the application using uwifi.

br101 avatar Oct 06 '16 11:10 br101