From: Viktor Szakats Date: Wed, 5 Feb 2025 14:32:11 +0000 (+0100) Subject: lib: include necessary headers for `inet_ntop`/`inet_pton` X-Git-Tag: curl-8_12_1~93 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6fc703904b2ed5e320abd66c9ef1efc894578fe9;p=thirdparty%2Fcurl.git lib: include necessary headers for `inet_ntop`/`inet_pton` Include `netinet/in.h` for FreeBSD/OpenBSD. Also include `sys/socket.h` just in case, based on earlier code in `tests/libtest/lib1960.c`. Also: - document these in `CMakeLists.txt`. - add a CI job testing FreeBSD with no unity and no test bundles. (without running tests to keep it fast) FreeBSD (autotools): ``` ../../../tests/libtest/lib1960.c:66:22: error: variable has incomplete type 'struct sockaddr_in' 66 | struct sockaddr_in serv_addr; | ^ ../../../tests/libtest/lib1960.c:66:10: note: forward declaration of 'struct sockaddr_in' 66 | struct sockaddr_in serv_addr; | ^ ``` Ref: https://github.com/curl/curl/actions/runs/13159721509/job/36725114118?pr=16188#step:3:5289 OpenBSD (cmake): ``` /home/runner/work/curl/curl/tests/libtest/lib1960.c:66:22: error: variable has incomplete type 'struct sockaddr_in' struct sockaddr_in serv_addr; ^ /home/runner/work/curl/curl/tests/libtest/lib1960.c:66:10: note: forward declaration of 'struct sockaddr_in' struct sockaddr_in serv_addr; ^ 1 error generated. ``` Ref: https://github.com/curl/curl/actions/runs/13159721509/job/36725102004?pr=16188#step:3:2166 Reported-by: CueXXIII on Github Fixes #16184 Follow-up to a3585c9576abccddbd27200058912cef900c3c0f #15543 Closes #16188 --- diff --git a/.github/workflows/non-native.yml b/.github/workflows/non-native.yml index 615aaeceb6..d67c3291ed 100644 --- a/.github/workflows/non-native.yml +++ b/.github/workflows/non-native.yml @@ -117,13 +117,14 @@ jobs: echo '::endgroup::' freebsd: - name: "FreeBSD, ${{ matrix.build == 'cmake' && 'CM' || 'AM' }} ${{ matrix.compiler }} openssl ${{ matrix.arch }}" + name: "FreeBSD, ${{ matrix.build == 'cmake' && 'CM' || 'AM' }} ${{ matrix.compiler }} openssl${{ matrix.desc }} ${{ matrix.arch }}" runs-on: ubuntu-latest timeout-minutes: 20 strategy: matrix: include: - { build: 'autotools', arch: 'x86_64', compiler: 'clang' } + - { build: 'cmake' , arch: 'x86_64', compiler: 'clang', options: '-DCMAKE_UNITY_BUILD=OFF -DCURL_TEST_BUNDLES=OFF', tflags: 'skiprun', desc: ' !unity !bundle !testrun' } - { build: 'autotools', arch: 'arm64', compiler: 'clang' } - { build: 'cmake' , arch: 'arm64', compiler: 'clang' } fail-fast: false @@ -148,14 +149,18 @@ jobs: --prefix="${HOME}"/install \ --with-openssl \ --with-brotli --enable-ldap --enable-ldaps --with-libidn2 --with-libssh2 --with-nghttp2 --with-gssapi \ - --disable-dependency-tracking || { tail -n 1000 config.log; false; } + --disable-dependency-tracking \ + ${{ matrix.options }} \ + || { tail -n 1000 config.log; false; } echo '::group::curl_config.h (raw)'; cat lib/curl_config.h || true; echo '::endgroup::' echo '::group::curl_config.h'; grep -F '#define' lib/curl_config.h | sort || true; echo '::endgroup::' time make -j3 install src/curl --disable --version if [ '${{ matrix.arch }}' = 'x86_64' ]; then # Slow on emulated CPU time make -j3 -C tests - time make test-ci V=1 TFLAGS='-j4' + if [ '${{ matrix.tflags }}' != 'skiprun' ]; then + time make test-ci V=1 TFLAGS='-j4' + fi fi echo '::group::build examples' time make -j3 examples @@ -179,6 +184,7 @@ jobs: -DENABLE_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \ -DCURL_USE_OPENSSL=ON \ -DCURL_USE_GSSAPI=ON \ + ${{ matrix.options }} \ || { cat bld/CMakeFiles/CMake*.yaml; false; } echo '::group::curl_config.h (raw)'; cat bld/lib/curl_config.h || true; echo '::endgroup::' echo '::group::curl_config.h'; grep -F '#define' bld/lib/curl_config.h | sort || true; echo '::endgroup::' @@ -186,7 +192,9 @@ jobs: bld/src/curl --disable --version if [ '${{ matrix.arch }}' = 'x86_64' ]; then # Slow on emulated CPU time cmake --build bld --config Debug --target testdeps - time cmake --build bld --config Debug --target test-ci + if [ '${{ matrix.tflags }}' != 'skiprun' ]; then + time cmake --build bld --config Debug --target test-ci + fi fi echo '::group::build examples' time cmake --build bld --config Debug --target curl-examples @@ -213,7 +221,8 @@ jobs: mkdir bld && cd bld && time ../configure --enable-unity --enable-test-bundles --enable-debug --enable-warnings --enable-werror \ --prefix="${HOME}"/install \ --with-openssl \ - --disable-dependency-tracking || { tail -n 1000 config.log; false; } + --disable-dependency-tracking \ + || { tail -n 1000 config.log; false; } echo '::group::curl_config.h (raw)'; cat lib/curl_config.h || true; echo '::endgroup::' echo '::group::curl_config.h'; grep -F '#define' lib/curl_config.h | sort || true; echo '::endgroup::' time gmake -j3 install diff --git a/CMakeLists.txt b/CMakeLists.txt index 30c0154be7..3c634cdd6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1767,8 +1767,8 @@ endif() if(APPLE) check_function_exists("mach_absolute_time" HAVE_MACH_ABSOLUTE_TIME) endif() -check_symbol_exists("inet_ntop" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP) # arpa/inet.h -check_symbol_exists("inet_pton" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON) # arpa/inet.h +check_symbol_exists("inet_ntop" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP) # arpa/inet.h netinet/in.h sys/socket.h +check_symbol_exists("inet_pton" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON) # arpa/inet.h netinet/in.h sys/socket.h check_symbol_exists("fsetxattr" "sys/xattr.h" HAVE_FSETXATTR) if(HAVE_FSETXATTR) diff --git a/lib/inet_ntop.h b/lib/inet_ntop.h index 3b90ed3b47..6bc7e27a79 100644 --- a/lib/inet_ntop.h +++ b/lib/inet_ntop.h @@ -29,6 +29,12 @@ char *Curl_inet_ntop(int af, const void *addr, char *buf, size_t size); #ifdef HAVE_INET_NTOP +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif diff --git a/lib/inet_pton.h b/lib/inet_pton.h index 50bce61342..915385fc25 100644 --- a/lib/inet_pton.h +++ b/lib/inet_pton.h @@ -29,6 +29,12 @@ int Curl_inet_pton(int, const char *, void *); #ifdef HAVE_INET_PTON +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif