Skip to content

Conversation

@cfriedt
Copy link
Member

@cfriedt cfriedt commented Oct 15, 2025

The net capture sample is likely one application that does rely on linking against the native C library rather than Picolibc, since it needs to hook into Linux's tun / tap interfaces.

However, after removing <zephyr/posix/...h> from the default search path, a number of conflicts appear between the native libc socket types and Zephyr's in net_ip.h.

Issue 97050 already captures this partially. However, there seems to be some confusion about POSIX headers and types and ISO C headers and types.

There are C libraries that do not include all of the necessary POSIX headers and types that Zephyr depends on. For example:

  • minimal libc
  • IAR
  • newlib
  • picolibc

The latter two might surprise some.

In any case, the work required to properly namespace net_ip.h constants and types is well out of the scope of the current release cycles, so this small workaround should suffice.

A non-exhaustive list of constants and types from net_ip.h that conflict with native types are

  • PF_INET
  • PF_INET6
  • PF_PACKET
  • PF_CAN
  • PF_LOCAL
  • SOCK_STREAM
  • SOCK_DGRAM
  • SOCK_RAW
  • struct iovec
  • struct msghdr
  • struct cmsghdr
  • struct sockaddr
  • struct sockaddr_storage

A non-exhaustive list of errors that arise are of the form(s) below:

In file included from $HOME/../zephyr/net/ethernet.h:21,
                 from $HOME/../samples/net/capture/src/main.c:15:
../zephyr/net/net_ip.h:45: warning: "PF_INET" redefined
   45 | #define PF_INET      1     /**< IP protocol family version 4. */
      |
/usr/include/bits/socket.h:45: note: this is the location of the previous \
  definition
   45 | #define PF_INET         2       /* IP protocol family.  */
      |
In file included from /usr/include/bits/socket.h:38:
$HOME/zephyrproject/zephyr/include/zephyr/net/net_ip.h:89:9: error: \
  redeclaration of enumerator ‘SOCK_STREAM’
   89 |         SOCK_STREAM = 1,           /**< Stream socket type   */
      |         ^~~~~~~~~~~
/usr/include/bits/socket_type.h:26:3: note: previous definition of \
  ‘SOCK_STREAM’ with type ‘enum __socket_type’
   26 |   SOCK_STREAM = 1,              /* Sequenced, reliable,...
      |   ^~~~~~~~~~~
$HOME/zephyrproject/zephyr/include/zephyr/net/net_ip.h:250:8: error: \
  redefinition of ‘struct iovec’
  250 | struct iovec {
      |        ^~~~~
In file included from /usr/include/sys/socket.h:26:
/usr/include/bits/types/struct_iovec.h:26:8: note: originally defined here
   26 | struct iovec
      |        ^~~~~

https://github.com/zephyrproject-rtos/zephyr/actions/runs/18482839735/job/52660791882?pr=97152

The net capture sample is likely one application that does rely on linking
against the native C library rather than Picolibc, since it needs to hook
into Linux's tun / tap interfaces.

However, after removing `<zephyr/posix/...h>` from the default search
path, a number of conflicts appear between the native libc socket types
and Zephyr's in `net_ip.h`.

Issue 97050 already captures this partially. However, there seems to be
some confusion about POSIX headers and types and ISO C headers and types.

There are C libraries that do not include all of the necessary POSIX
headers and types that Zephyr depends on. For example:

* minimal libc
* IAR
* newlib
* picolibc

The latter two might surprise some.

In any case, the work required to properly namespace `net_ip.h` constants
and types is well out of the scope of the current release cycles, so this
small workaround should suffice.

A non-exhaustive list of constants and types from `net_ip.h` that conflict
with native types are

* PF_INET
* PF_INET6
* PF_PACKET
* PF_CAN
* PF_LOCAL
* SOCK_STREAM
* SOCK_DGRAM
* SOCK_RAW
* struct iovec
* struct msghdr
* struct cmsghdr
* struct sockaddr
* struct sockaddr_storage

A non-exhaustive list of errors that arise are of the form(s) below:
```shell
In file included from $HOME/../zephyr/net/ethernet.h:21,
                 from $HOME/../samples/net/capture/src/main.c:15:
../zephyr/net/net_ip.h:45: warning: "PF_INET" redefined
   45 | #define PF_INET      1     /**< IP protocol family version 4. */
      |
/usr/include/bits/socket.h:45: note: this is the location of the previous \
  definition
   45 | #define PF_INET         2       /* IP protocol family.  */
      |
In file included from /usr/include/bits/socket.h:38:
$HOME/zephyrproject/zephyr/include/zephyr/net/net_ip.h:89:9: error: \
  redeclaration of enumerator ‘SOCK_STREAM’
   89 |         SOCK_STREAM = 1,           /**< Stream socket type   */
      |         ^~~~~~~~~~~
/usr/include/bits/socket_type.h:26:3: note: previous definition of \
  ‘SOCK_STREAM’ with type ‘enum __socket_type’
   26 |   SOCK_STREAM = 1,              /* Sequenced, reliable,...
      |   ^~~~~~~~~~~
$HOME/zephyrproject/zephyr/include/zephyr/net/net_ip.h:250:8: error: \
  redefinition of ‘struct iovec’
  250 | struct iovec {
      |        ^~~~~
In file included from /usr/include/sys/socket.h:26:
/usr/include/bits/types/struct_iovec.h:26:8: note: originally defined here
   26 | struct iovec
      |        ^~~~~
```

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
@sonarqubecloud
Copy link

@henrikbrixandersen henrikbrixandersen merged commit 4fd0323 into zephyrproject-rtos:main Oct 17, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants