seemoo-lab / owl

An open Apple Wireless Direct Link (AWDL) implementation written in C
https://owlink.org
GNU General Public License v3.0
1.21k stars 86 forks source link

build error: redefinition of 'struct ethhdr' #78

Open WhyNotHugo opened 1 year ago

WhyNotHugo commented 1 year ago

I'm building on Alpine Linux. I installed the following dependencies (based on the hints in the README):

libpcap-dev libev-dev libnl3-dev

The make step of the build process fails with:

> make 
[  2%] Building C object CMakeFiles/radiotap.dir/radiotap/radiotap.c.o
/home/hugo/clones/github.com/seemoo-lab/owl/radiotap/radiotap.c: In function 'ieee80211_radiotap_iterator_init':
/home/hugo/clones/github.com/seemoo-lab/owl/radiotap/radiotap.c:113:34: warning: taking address of packed member of 'struct ieee80211_radiotap_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
  113 |         iterator->_next_bitmap = &radiotap_header->it_present;
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
[  5%] Linking C static library libradiotap.a
[  5%] Built target radiotap
[  8%] Building C object src/CMakeFiles/awdl.dir/log.c.o
[ 10%] Building C object src/CMakeFiles/awdl.dir/state.c.o
[ 13%] Building C object src/CMakeFiles/awdl.dir/election.c.o
[ 16%] Building C object src/CMakeFiles/awdl.dir/sync.c.o
[ 18%] Building C object src/CMakeFiles/awdl.dir/channel.c.o
[ 21%] Building C object src/CMakeFiles/awdl.dir/schedule.c.o
[ 24%] Building C object src/CMakeFiles/awdl.dir/tx.c.o
[ 27%] Building C object src/CMakeFiles/awdl.dir/rx.c.o
[ 29%] Building C object src/CMakeFiles/awdl.dir/frame.c.o
[ 32%] Building C object src/CMakeFiles/awdl.dir/crc32.c.o
[ 35%] Building C object src/CMakeFiles/awdl.dir/wire.c.o
[ 37%] Building C object src/CMakeFiles/awdl.dir/peers.c.o
[ 40%] Building C object src/CMakeFiles/awdl.dir/version.c.o
[ 43%] Building C object src/CMakeFiles/awdl.dir/hashmap.c.o
[ 45%] Building C object src/CMakeFiles/awdl.dir/siphash24.c.o
[ 48%] Building C object src/CMakeFiles/awdl.dir/circular_buffer.c.o
[ 51%] Linking C static library libawdl.a
[ 51%] Built target awdl
[ 54%] Building C object daemon/CMakeFiles/owl.dir/io.c.o
In file included from /usr/include/netinet/ether.h:8,
                 from /home/hugo/clones/github.com/seemoo-lab/owl/daemon/io.h:31,
                 from /home/hugo/clones/github.com/seemoo-lab/owl/daemon/io.c:35:
/usr/include/netinet/if_ether.h:115:8: error: redefinition of 'struct ethhdr'
  115 | struct ethhdr {
      |        ^~~~~~
In file included from /usr/include/linux/if_tun.h:21,
                 from /home/hugo/clones/github.com/seemoo-lab/owl/daemon/io.c:28:
/usr/include/linux/if_ether.h:173:8: note: originally defined here
  173 | struct ethhdr {
      |        ^~~~~~
make[2]: *** [daemon/CMakeFiles/owl.dir/build.make:76: daemon/CMakeFiles/owl.dir/io.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:243: daemon/CMakeFiles/owl.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
WhyNotHugo commented 1 year ago

So I understand the issue: both files being included define struct ethhdr. However, both of them defined other types which are used, so removing either of them is not an option.

WhyNotHugo commented 1 year ago

I tired hacking around this with this horrible patch:

diff --git a/daemon/io.c b/daemon/io.c
index 42688f5..b41e8fb 100644
--- a/daemon/io.c
+++ b/daemon/io.c
@@ -25,7 +25,10 @@
 #include <net/if.h>
 #include <sys/ioctl.h>
 #ifndef __APPLE__
-#include <linux/if_tun.h>
+/* #include <linux/if_tun.h> */
+#define IFF_NO_PI  0x1000
+#define IFF_TAP        0x0002
+#define TUNSETIFF     _IOW('T', 202, int)
 #else
 #include <sys/sys_domain.h>
 #include <sys/kern_control.h>

But build now fails with another unrelated error:

> make
[  5%] Built target radiotap
[ 51%] Built target awdl
[ 64%] Built target owl
[ 67%] Building CXX object googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
In file included from /home/hugo/clones/github.com/seemoo-lab/owl/googletest/googletest/src/gtest-all.cc:42:
/home/hugo/clones/github.com/seemoo-lab/owl/googletest/googletest/src/gtest-death-test.cc: In function 'bool testing::internal::StackGrowsDown()':
/home/hugo/clones/github.com/seemoo-lab/owl/googletest/googletest/src/gtest-death-test.cc:1301:24: error: 'dummy' may be used uninitialized [-Werror=maybe-uninitialized]
 1301 |   StackLowerThanAddress(&dummy, &result);
      |   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/home/hugo/clones/github.com/seemoo-lab/owl/googletest/googletest/src/gtest-death-test.cc:1290:13: note: by argument 1 of type 'const void*' to 'void testing::internal::StackLowerThanAddress(const void*, bool*)' declared here
 1290 | static void StackLowerThanAddress(const void* ptr, bool* result) {
      |             ^~~~~~~~~~~~~~~~~~~~~
/home/hugo/clones/github.com/seemoo-lab/owl/googletest/googletest/src/gtest-death-test.cc:1299:7: note: 'dummy' declared here
 1299 |   int dummy;
      |       ^~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [googletest/googletest/CMakeFiles/gtest.dir/build.make:76: googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:322: googletest/googletest/CMakeFiles/gtest.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
rela81 commented 1 year ago

Thanks to your "horrible" patch I was able to compile owl on Alpine successfully. I didn't get any further errors. You could also try to update googletest as described in issue #50

WhyNotHugo commented 1 year ago

Thanks for the pointer to https://github.com/seemoo-lab/owl/issues/50. I've submitted https://github.com/seemoo-lab/owl/issues/80 which fixes that other issue.

I'm still unsure what to do about this patch of mine, it doesn't seem clean enough to include on the project, but I also can't think of any cleaner approach.