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

@ -154,12 +154,6 @@
/* Define to the function return type for send. */
#define SEND_TYPE_RETV int
/* Must always use local implementations on Windows. */
/* Define to 1 if you have an IPv6 capable working inet_ntop function. */
/* #undef HAVE_INET_NTOP */
/* Define to 1 if you have an IPv6 capable working inet_pton function. */
/* #undef HAVE_INET_PTON */
/* Define to 1 if you have the `basename' function. */
#ifdef __MINGW32__
#define HAVE_BASENAME 1

View file

@ -336,12 +336,6 @@
/* Define to 1 if you have the <ifaddrs.h> header file. */
#cmakedefine HAVE_IFADDRS_H 1
/* Define to 1 if you have an IPv6 capable working inet_ntop function. */
#cmakedefine HAVE_INET_NTOP 1
/* Define to 1 if you have an IPv6 capable working inet_pton function. */
#cmakedefine HAVE_INET_PTON 1
/* Define to 1 if symbol `sa_family_t' exists */
#cmakedefine HAVE_SA_FAMILY_T 1

View file

@ -18,8 +18,6 @@
*/
#include "curl_setup.h"
#ifndef HAVE_INET_NTOP
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
@ -219,4 +217,3 @@ char *curlx_inet_ntop(int af, const void *src, char *buf, size_t size)
return NULL;
}
}
#endif /* HAVE_INET_NTOP */

View file

@ -25,26 +25,6 @@
***************************************************************************/
#include "curl_setup.h"
#ifdef HAVE_INET_NTOP
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifndef _WIN32
#include <sys/socket.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef __AMIGA__
#define curlx_inet_ntop(af, src, buf, size) \
(char *)inet_ntop(af, CURL_UNCONST(src), (unsigned char *)(buf), \
(curl_socklen_t)(size))
#else
#define curlx_inet_ntop(af, src, buf, size) \
inet_ntop(af, src, buf, (curl_socklen_t)(size))
#endif
#else
char *curlx_inet_ntop(int af, const void *src, char *buf, size_t size);
#endif /* HAVE_INET_NTOP */
#endif /* HEADER_CURL_INET_NTOP_H */

View file

@ -19,8 +19,6 @@
*/
#include "curl_setup.h"
#ifndef HAVE_INET_PTON
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
@ -217,5 +215,3 @@ int curlx_inet_pton(int af, const char *src, void *dst)
}
/* NOTREACHED */
}
#endif /* HAVE_INET_PTON */

View file

@ -25,25 +25,6 @@
***************************************************************************/
#include "curl_setup.h"
#ifdef HAVE_INET_PTON
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifndef _WIN32
#include <sys/socket.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef __AMIGA__
#define curlx_inet_pton(x, y, z) \
inet_pton(x, (unsigned char *)CURL_UNCONST(y), z)
#else
#define curlx_inet_pton(x, y, z) \
inet_pton(x, y, z)
#endif
#else
int curlx_inet_pton(int af, const char *src, void *dst);
#endif /* HAVE_INET_PTON */
#endif /* HEADER_CURL_INET_PTON_H */