apache / nuttx-apps

Apache NuttX Apps is a collection of tools, shells, network utilities, libraries, interpreters and can be used with the NuttX RTOS
https://nuttx.apache.org/
Apache License 2.0
289 stars 544 forks source link

[BUG] Implicit definiton of accept4 function when building simulator on Arch Linux #2632

Closed linguini1 closed 1 month ago

linguini1 commented 1 month ago

Description / Steps to reproduce the issue

I was attempting to build the Simulator with the tcpblaster configuration to test out some NuttX networking, but I ran into an implicit function definition error:

[linguini@pastabox nuttx]$ make -j
CC:  tcpblaster_server.c
LN: platform/board to /home/linguini/cuinspace/pico-nuttx/apps/platform/dummy
tcpblaster_server.c: In function ‘tcpblaster_server’:
tcpblaster_server.c:159:14: error: implicit declaration of function ‘accept4’; did you mean ‘accept’? [-Wimplicit-function-declaration]
  159 |   acceptsd = accept4(listensd, (FAR struct sockaddr *)&myaddr, &addrlen,
      |              ^~~~~~~
      |              accept
make[3]: *** [Makefile:92: tcpblaster_server.hobj] Error 1
make[2]: *** [Makefile:53: /home/linguini/cuinspace/pico-nuttx/apps/examples/tcpblaster_context] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile:180: context] Error 2
make: *** [tools/Unix.mk:457: /home/linguini/cuinspace/pico-nuttx/apps/.context] Error 2
make: *** Waiting for unfinished jobs....

Looking at the manpages for accept4, it seems to require that _GNU_SOURCE be defined before the header is included. I added -D_GNU_SOURCE to this line of the TCP blaster example, and it fixed the build issue on my machine. Others that I am working with were able to build the example without any issues on Ubuntu, so I wanted to check and see if I am perhaps taking the wrong approach before I open a PR to permanently add that change to the example.

I followed the first three steps listed in the simulator docs here.

make distclean
./tools/configure.sh sim:tcpblaster
make

On which OS does this issue occur?

[Linux]

What is the version of your OS?

Linux 6.10.10-arch1-1 x86_64 GNU/Linux

NuttX Version

master

Issue Architecture

[simulator]

Issue Area

[Applications], [Build System], [Configuring], [Networking]

Verification

cederom commented 1 month ago

Thanks @linguini1 yes this problem was introduced recently by https://github.com/apache/nuttx-apps/pull/2595 we are looking for a solution should show up soon :-)

linguini1 commented 1 month ago

Thanks @linguini1 yes this problem was introduced recently by https://github.com/apache/nuttx-apps/pull/2595 we are looking for a solution should show up soon :-)

Ah, I missed seeing that! Would it be preferable for me to open a PR to add this new define, or shall I leave the solution to the original author?

cederom commented 1 month ago

Lets wait for the original change author to reply.. accept4 is a non-standard extension that increases security.. we already noticed problems on macOS that does not have that call implemented.. no clue how _GNU_SOURCE will impact other compilers / compatibility avalanche.. but your hint may be right the solution!! :-)

xiaoxiang781216 commented 1 month ago

we can call accept4 on nuttx, but call accept on host.