obgm / libcoap

A CoAP (RFC 7252) implementation in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build issue with ifaddr.h

hasheddan opened this issue · comments

Environment

  • Build System: CMake (via Zephyr west)
  • Operating System: Linux
  • Operating System Version: Ubuntu 24.04
  • Hosted Environment: Zephyr

libcoap Configuration Summary

Copy the "libcoap Configuration Summary" output lines here after running
./configure (with any options that you have specified)
or
cmake .. (with any -D options that you have specified)
or if neither of the above two methods is used (do from within the libcoap directory)
git describe --tags

Problem Description

Seeing the following build error:

/__w/golioth-firmware-sdk/golioth-firmware-sdk/modules/lib/golioth-firmware-sdk/external/libcoap/src/coap_address.c:160:10: fatal error: ifaddrs.h: No such file or directory
  160 | #include <ifaddrs.h>
      |          ^~~~~~~~~~~

Which I believe is due to the fact that ifaddrs.h is not included in the Zephyr minimal libc.

I can see that this addition was wrapped to be excluded when ESP IDF is being used -- perhaps a similar conditional for Zephyr could be added. I am happy to implement if so.

Expected Behavior

I expected for compilation to be successful.

Actual Behavior

Compilation failed with steps described above.

Steps to reproduce

A full reproduction of the build can be found here.

I think that this is the change you need to try out.

diff --git a/src/coap_address.c b/src/coap_address.c
index ab63681..23b1e82 100644
--- a/src/coap_address.c
+++ b/src/coap_address.c
@@ -139,7 +139,7 @@ coap_is_mcast(const coap_address_t *a) {
   return 0;
 }
 
-#if !defined(WIN32)
+#if !defined(WIN32) && !defined(__ZEPHYR__)
 
 #ifndef COAP_BCST_CNT
 #define COAP_BCST_CNT 15

I can look to see if there is a better fix later.

Thanks @mrdeep1! I have verified that this fixes the observed error and opened #1218 with the fix.