]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: include necessary headers for `inet_ntop`/`inet_pton`
authorViktor Szakats <commit@vsz.me>
Wed, 5 Feb 2025 14:32:11 +0000 (15:32 +0100)
committerViktor Szakats <commit@vsz.me>
Wed, 5 Feb 2025 15:29:03 +0000 (16:29 +0100)
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

.github/workflows/non-native.yml
CMakeLists.txt
lib/inet_ntop.h
lib/inet_pton.h

index 615aaeceb62311d33203e93400caf635a4f83b3b..d67c3291ed0369d3b310608b25cd30b5bbae3f48 100644 (file)
@@ -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
index 30c0154be78b3308db9f15504dded393f02c6d29..3c634cdd6a824ea9d7dff843bfee901aa96a3167 100644 (file)
@@ -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)
index 3b90ed3b47babe67778bebfff14938c5f9668bbe..6bc7e27a79f2c36440bae77cabfe171d5e5db52e 100644 (file)
 char *Curl_inet_ntop(int af, const void *addr, char *buf, size_t size);
 
 #ifdef HAVE_INET_NTOP
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
 #ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #endif
index 50bce613427e1b79a19407aee64ae7e10a181d45..915385fc257315ab3b4536715c158886777873ee 100644 (file)
 int Curl_inet_pton(int, const char *, void *);
 
 #ifdef HAVE_INET_PTON
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
 #ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #endif