build: always use local inet_pton()/inet_ntop() implementations

Also repurpose existing build-time feature checks into unit test 1961,
to verify.

Prior to this patch these functions were auto-detected with both
autotools and cmake. In case of autotools there was an extra
verification phase ensuring the functions work as expected. This step
required running the function, thus was limited to non-cross-builds. For
cross-builds and CMake it always used the system implementation if
present. On Windows it always used the local implementation, because
availability/use is complicated there.

After this patch all platforms, always use the local implementation,
which is known to be accurate. This makes curl behave more consistently,
and simplifies the build process, a fixes cross-builds and CMake
auto-detection differences.

Also:
- test1960: enable unconditionally.
- checksrc: disallow globally, allowlist in `block_ip.c` example.
- dnsd: verify ntop result for NULL before passing to printf.

Ref: https://github.com/curl/curl/pull/22137#issuecomment-4797440983
Ref: #22137
Ref: 8537a5b0bc #16577

Closes #22170
This commit is contained in:
Viktor Szakats 2026-06-25 12:48:26 +02:00
parent a62e08c5eb
commit 39dec13ec0
No known key found for this signature in database
22 changed files with 214 additions and 448 deletions

View file

@ -36,6 +36,8 @@ UTILS_H = testutil.h testtrace.h unitcheck.h
CURLX_C = \
../../lib/curl_threads.c \
../../lib/curlx/fopen.c \
../../lib/curlx/inet_ntop.c \
../../lib/curlx/inet_pton.c \
../../lib/curlx/multibyte.c \
../../lib/curlx/strcopy.c \
../../lib/curlx/strerr.c \

View file

@ -47,6 +47,8 @@ extern int unitfail; /* for unittests */
#include "curlx/base64.h" /* for curlx_base64* */
#include "curlx/dynbuf.h" /* for curlx_dyn_*() */
#include "curlx/fopen.h" /* for curlx_f*() */
#include "curlx/inet_ntop.h" /* for curlx_inet_ntop() */
#include "curlx/inet_pton.h" /* for curlx_inet_pton() */
#include "curlx/strcopy.h" /* for curlx_strcopy() */
#include "curlx/strerr.h" /* for curlx_strerror() */
#include "curlx/strparse.h" /* for curlx_str_* parsing functions */

View file

@ -23,8 +23,6 @@
***************************************************************************/
#include "first.h"
#ifdef HAVE_INET_PTON
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@ -62,12 +60,6 @@ static int sockopt_cb(void *clientp,
return CURL_SOCKOPT_ALREADY_CONNECTED;
}
#ifdef __AMIGA__
#define my_inet_pton(x, y, z) inet_pton(x, (unsigned char *)CURL_UNCONST(y), z)
#else
#define my_inet_pton(x, y, z) inet_pton(x, y, z)
#endif
/* Expected args: URL IP PORT */
static CURLcode test_lib1960(const char *URL)
{
@ -104,8 +96,8 @@ static CURLcode test_lib1960(const char *URL)
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons((unsigned short)port);
if(my_inet_pton(AF_INET, libtest_arg2, &serv_addr.sin_addr) <= 0) {
curl_mfprintf(stderr, "inet_pton failed\n");
if(curlx_inet_pton(AF_INET, libtest_arg2, &serv_addr.sin_addr) <= 0) {
curl_mfprintf(stderr, "curlx_inet_pton() failed\n");
goto test_cleanup;
}
@ -143,11 +135,3 @@ test_cleanup:
return result;
}
#else
static CURLcode test_lib1960(const char *URL)
{
(void)URL;
curl_mprintf("lacks inet_pton\n");
return CURLE_OK;
}
#endif