Skip to content

Commit

Permalink
build: prefer USE_IPV6 macro internally (was: ENABLE_IPV6)
Browse files Browse the repository at this point in the history
Before this patch, two macros were used to guard IPv6 features in curl
sources: `ENABLE_IPV6` and `USE_IPV6`. This patch makes the source use
the latter for consistency with other similar switches.

`-DENABLE_IPV6` remains accepted for compatibility as a synonym for
`-DUSE_IPV6`, when passed to the compiler.

`ENABLE_IPV6` also remains the name of the CMake and `Makefile.vc`
options to control this feature.

Closes #13349
  • Loading branch information
vszakats committed Apr 13, 2024
1 parent de66e8a commit e411c98
Show file tree
Hide file tree
Showing 47 changed files with 197 additions and 196 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -303,6 +303,9 @@ if(ENABLE_IPV6 AND NOT WIN32)
list(APPEND CURL_LIBS "-framework SystemConfiguration")
endif()
endif()
if(ENABLE_IPV6)
set(USE_IPV6 ON)
endif()

find_package(Perl)

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -1700,7 +1700,7 @@ int main(void)

if test "$ipv6" = yes; then
curl_ipv6_msg="enabled"
AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
AC_DEFINE(USE_IPV6, 1, [Define if you want to enable IPv6 support])
IPV6_ENABLED=1
AC_SUBST(IPV6_ENABLED)

Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile.mk
Expand Up @@ -254,7 +254,7 @@ endif
endif

ifneq ($(findstring -ipv6,$(CFG)),)
CPPFLAGS += -DENABLE_IPV6
CPPFLAGS += -DUSE_IPV6
endif

ifneq ($(findstring -watt,$(CFG))$(MSDOS),)
Expand Down
2 changes: 1 addition & 1 deletion lib/altsvc.c
Expand Up @@ -252,7 +252,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp)
CURLcode result = Curl_gmtime(as->expires, &stamp);
if(result)
return result;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
else {
char ipv6_unused[16];
if(1 == Curl_inet_pton(AF_INET6, as->dst.host, ipv6_unused)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/asyn-ares.c
Expand Up @@ -539,7 +539,7 @@ static void compound_results(struct thread_data *res,
if(!ai)
return;

#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
#ifdef USE_IPV6 /* CURLRES_IPV6 */
if(res->temp_ai && res->temp_ai->ai_family == PF_INET6) {
/* We have results already, put the new IPv6 entries at the head of the
list. */
Expand Down Expand Up @@ -684,7 +684,7 @@ static struct Curl_addrinfo *ares2addr(struct ares_addrinfo_node *node)
/* settle family-specific sockaddr structure size. */
if(ai->ai_family == AF_INET)
ss_size = sizeof(struct sockaddr_in);
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
else if(ai->ai_family == AF_INET6)
ss_size = sizeof(struct sockaddr_in6);
#endif
Expand Down Expand Up @@ -932,7 +932,7 @@ CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data,
CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data,
const char *local_ip6)
{
#if defined(HAVE_CARES_SET_LOCAL) && defined(ENABLE_IPV6)
#if defined(HAVE_CARES_SET_LOCAL) && defined(USE_IPV6)
unsigned char a6[INET6_ADDRSTRLEN];

if((!local_ip6) || (local_ip6[0] == 0)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/asyn-thread.c
Expand Up @@ -325,7 +325,7 @@ query_complete(DWORD err, DWORD bytes, LPWSAOVERLAPPED overlapped)
/* settle family-specific sockaddr structure size. */
if(ai->ai_family == AF_INET)
ss_size = sizeof(struct sockaddr_in);
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
else if(ai->ai_family == AF_INET6)
ss_size = sizeof(struct sockaddr_in6);
#endif
Expand Down Expand Up @@ -444,7 +444,7 @@ query_complete(DWORD err, DWORD bytes, LPWSAOVERLAPPED overlapped)
/*
* getaddrinfo_thread() resolves a name and then exits.
*
* For builds without ARES, but with ENABLE_IPV6, create a resolver thread
* For builds without ARES, but with USE_IPV6, create a resolver thread
* and wait on it.
*/
static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg)
Expand Down
26 changes: 13 additions & 13 deletions lib/cf-socket.c
Expand Up @@ -81,7 +81,7 @@
#include "memdebug.h"


#if defined(ENABLE_IPV6) && defined(IPV6_V6ONLY) && defined(_WIN32)
#if defined(USE_IPV6) && defined(IPV6_V6ONLY) && defined(_WIN32)
/* It makes support for IPv4-mapped IPv6 addresses.
* Linux kernel, NetBSD, FreeBSD and Darwin: default is off;
* Windows Vista and later: default is on;
Expand Down Expand Up @@ -287,7 +287,7 @@ static CURLcode socket_open(struct Curl_easy *data,
/* no socket, no connection */
return CURLE_COULDNT_CONNECT;

#if defined(ENABLE_IPV6) && defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
#if defined(USE_IPV6) && defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
if(data->conn->scope_id && (addr->family == AF_INET6)) {
struct sockaddr_in6 * const sa6 = (void *)&addr->sa_addr;
sa6->sin6_scope_id = data->conn->scope_id;
Expand Down Expand Up @@ -405,7 +405,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,
struct sockaddr *sock = (struct sockaddr *)&sa; /* bind to this address */
curl_socklen_t sizeof_sa = 0; /* size of the data sock points to */
struct sockaddr_in *si4 = (struct sockaddr_in *)&sa;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
struct sockaddr_in6 *si6 = (struct sockaddr_in6 *)&sa;
#endif

Expand All @@ -419,7 +419,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,
#ifdef IP_BIND_ADDRESS_NO_PORT
int on = 1;
#endif
#ifndef ENABLE_IPV6
#ifndef USE_IPV6
(void)scope;
#endif

Expand Down Expand Up @@ -475,7 +475,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,
#endif

switch(Curl_if2ip(af,
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
scope, conn->scope_id,
#endif
dev, myhost, sizeof(myhost))) {
Expand Down Expand Up @@ -514,7 +514,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,

if(af == AF_INET)
conn->ip_version = CURL_IPRESOLVE_V4;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
else if(af == AF_INET6)
conn->ip_version = CURL_IPRESOLVE_V6;
#endif
Expand Down Expand Up @@ -547,7 +547,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,
}

if(done > 0) {
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
/* IPv6 address */
if(af == AF_INET6) {
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
Expand Down Expand Up @@ -596,7 +596,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,
}
else {
/* no device was given, prepare sa to match af's needs */
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
if(af == AF_INET6) {
si6->sin6_family = AF_INET6;
si6->sin6_port = htons(port);
Expand Down Expand Up @@ -639,7 +639,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,
/* We reuse/clobber the port variable here below */
if(sock->sa_family == AF_INET)
si4->sin_port = ntohs(port);
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
else
si6->sin6_port = ntohs(port);
#endif
Expand Down Expand Up @@ -991,7 +991,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf,
if(result)
goto out;

#ifdef ENABLE_IPV6
#ifdef USE_IPV6
if(ctx->addr.family == AF_INET6) {
set_ipv6_v6only(ctx->sock, 0);
infof(data, " Trying [%s]:%d...", ctx->ip.remote_ip, ctx->ip.remote_port);
Expand All @@ -1000,7 +1000,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf,
#endif
infof(data, " Trying %s:%d...", ctx->ip.remote_ip, ctx->ip.remote_port);

#ifdef ENABLE_IPV6
#ifdef USE_IPV6
is_tcp = (ctx->addr.family == AF_INET
|| ctx->addr.family == AF_INET6) &&
ctx->addr.socktype == SOCK_STREAM;
Expand Down Expand Up @@ -1037,7 +1037,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf,
#ifndef CURL_DISABLE_BINDLOCAL
/* possibly bind the local end to an IP, interface or port */
if(ctx->addr.family == AF_INET
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
|| ctx->addr.family == AF_INET6
#endif
) {
Expand Down Expand Up @@ -1449,7 +1449,7 @@ static void cf_socket_active(struct Curl_cfilter *cf, struct Curl_easy *data)
/* the first socket info gets some specials */
if(cf->sockindex == FIRSTSOCKET) {
cf->conn->remote_addr = &ctx->addr;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
cf->conn->bits.ipv6 = (ctx->addr.family == AF_INET6)? TRUE : FALSE;
#endif
Curl_persistconninfo(data, cf->conn, &ctx->ip);
Expand Down
2 changes: 1 addition & 1 deletion lib/config-os400.h
Expand Up @@ -57,7 +57,7 @@
#undef NEED_REENTRANT

/* Define if you want to enable IPv6 support */
#define ENABLE_IPV6
#define USE_IPV6

/* Define if struct sockaddr_in6 has the sin6_scope_id member */
#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1
Expand Down
2 changes: 1 addition & 1 deletion lib/config-plan9.h
Expand Up @@ -28,7 +28,7 @@
#define CURL_CA_BUNDLE "/sys/lib/tls/ca.pem"
#define CURL_CA_PATH "/sys/lib/tls"
#define CURL_STATICLIB 1
#define ENABLE_IPV6 1
#define USE_IPV6 1
#define CURL_DISABLE_LDAP 1

#define NEED_REENTRANT 1
Expand Down
5 changes: 1 addition & 4 deletions lib/config-riscos.h
Expand Up @@ -55,7 +55,7 @@
#undef NEED_REENTRANT

/* Define if you want to enable IPv6 support */
#undef ENABLE_IPV6
#undef USE_IPV6

/* Define if struct sockaddr_in6 has the sin6_scope_id member */
#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1
Expand All @@ -66,9 +66,6 @@
/* Define this as a suitable file to read random data from */
#undef RANDOM_FILE

/* Define if you want to enable IPv6 support */
#undef ENABLE_IPV6

/* Define if you have the alarm function. */
#define HAVE_ALARM

Expand Down
4 changes: 0 additions & 4 deletions lib/config-win32.h
Expand Up @@ -509,8 +509,4 @@ Vista
/* If you want to build curl with the built-in manual */
#define USE_MANUAL 1

#if defined(USE_IPV6)
# define ENABLE_IPV6 1
#endif

#endif /* HEADER_CURL_CONFIG_WIN32_H */
2 changes: 1 addition & 1 deletion lib/conncache.c
Expand Up @@ -140,7 +140,7 @@ static void hashkey(struct connectdata *conn, char *buf, size_t len)
hostname = conn->host.name;

/* put the numbers first so that the hostname gets cut off if too long */
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
msnprintf(buf, len, "%u/%ld/%s", conn->scope_id, port, hostname);
#else
msnprintf(buf, len, "%ld/%s", port, hostname);
Expand Down
10 changes: 5 additions & 5 deletions lib/connect.c
Expand Up @@ -195,7 +195,7 @@ bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
char *addr, int *port)
{
struct sockaddr_in *si = NULL;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
struct sockaddr_in6 *si6 = NULL;
#endif
#if (defined(HAVE_SYS_UN_H) || defined(WIN32_SOCKADDR_UN)) && defined(AF_UNIX)
Expand All @@ -214,7 +214,7 @@ bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
return TRUE;
}
break;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
case AF_INET6:
si6 = (struct sockaddr_in6 *)(void *) sa;
if(Curl_inet_ntop(sa->sa_family, &si6->sin6_addr,
Expand Down Expand Up @@ -401,7 +401,7 @@ static CURLcode eyeballer_new(struct eyeballer **pballer,
return CURLE_OUT_OF_MEMORY;

baller->name = ((ai_family == AF_INET)? "ipv4" : (
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
(ai_family == AF_INET6)? "ipv6" :
#endif
"ip"));
Expand Down Expand Up @@ -779,7 +779,7 @@ static CURLcode start_connect(struct Curl_cfilter *cf,
/* any IP version is allowed */
ai_family0 = remotehost->addr?
remotehost->addr->ai_family : 0;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
ai_family1 = ai_family0 == AF_INET6 ?
AF_INET : AF_INET6;
#else
Expand All @@ -790,7 +790,7 @@ static CURLcode start_connect(struct Curl_cfilter *cf,
/* only one IP version is allowed */
ai_family0 = (conn->ip_version == CURL_IPRESOLVE_V4) ?
AF_INET :
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
AF_INET6;
#else
AF_UNSPEC;
Expand Down
18 changes: 9 additions & 9 deletions lib/curl_addrinfo.c
Expand Up @@ -130,7 +130,7 @@ Curl_getaddrinfo_ex(const char *nodename,
/* settle family-specific sockaddr structure size. */
if(ai->ai_family == AF_INET)
ss_size = sizeof(struct sockaddr_in);
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
else if(ai->ai_family == AF_INET6)
ss_size = sizeof(struct sockaddr_in6);
#endif
Expand Down Expand Up @@ -259,7 +259,7 @@ Curl_he2ai(const struct hostent *he, int port)
struct Curl_addrinfo *prevai = NULL;
struct Curl_addrinfo *firstai = NULL;
struct sockaddr_in *addr;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
struct sockaddr_in6 *addr6;
#endif
CURLcode result = CURLE_OK;
Expand All @@ -275,7 +275,7 @@ Curl_he2ai(const struct hostent *he, int port)
for(i = 0; (curr = he->h_addr_list[i]) != NULL; i++) {
size_t ss_size;
size_t namelen = strlen(he->h_name) + 1; /* include null-terminator */
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
if(he->h_addrtype == AF_INET6)
ss_size = sizeof(struct sockaddr_in6);
else
Expand Down Expand Up @@ -321,7 +321,7 @@ Curl_he2ai(const struct hostent *he, int port)
addr->sin_port = htons((unsigned short)port);
break;

#ifdef ENABLE_IPV6
#ifdef USE_IPV6
case AF_INET6:
addr6 = (void *)ai->ai_addr; /* storage area for this info */

Expand All @@ -348,7 +348,7 @@ struct namebuff {
struct hostent hostentry;
union {
struct in_addr ina4;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
struct in6_addr ina6;
#endif
} addrentry;
Expand Down Expand Up @@ -401,7 +401,7 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port)
addrentry = (void *)&buf->addrentry.ina4;
memcpy(addrentry, inaddr, sizeof(struct in_addr));
break;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
case AF_INET6:
addrsize = sizeof(struct in6_addr);
addrentry = (void *)&buf->addrentry.ina6;
Expand Down Expand Up @@ -447,7 +447,7 @@ struct Curl_addrinfo *Curl_str2addr(char *address, int port)
if(Curl_inet_pton(AF_INET, address, &in) > 0)
/* This is a dotted IP address 123.123.123.123-style */
return Curl_ip2addr(AF_INET, &in, address, port);
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
{
struct in6_addr in6;
if(Curl_inet_pton(AF_INET6, address, &in6) > 0)
Expand Down Expand Up @@ -570,7 +570,7 @@ void Curl_addrinfo_set_port(struct Curl_addrinfo *addrinfo, int port)
{
struct Curl_addrinfo *ca;
struct sockaddr_in *addr;
#ifdef ENABLE_IPV6
#ifdef USE_IPV6
struct sockaddr_in6 *addr6;
#endif
for(ca = addrinfo; ca != NULL; ca = ca->ai_next) {
Expand All @@ -580,7 +580,7 @@ void Curl_addrinfo_set_port(struct Curl_addrinfo *addrinfo, int port)
addr->sin_port = htons((unsigned short)port);
break;

#ifdef ENABLE_IPV6
#ifdef USE_IPV6
case AF_INET6:
addr6 = (void *)ca->ai_addr; /* storage area for this info */
addr6->sin6_port = htons((unsigned short)port);
Expand Down
2 changes: 1 addition & 1 deletion lib/curl_config.h.cmake
Expand Up @@ -163,7 +163,7 @@
#cmakedefine USE_WIN32_LDAP 1

/* Define if you want to enable IPv6 support */
#cmakedefine ENABLE_IPV6 1
#cmakedefine USE_IPV6 1

/* Define to 1 if you have the alarm function. */
#cmakedefine HAVE_ALARM 1
Expand Down

0 comments on commit e411c98

Please sign in to comment.