Skip to content

Commit

Permalink
Remove unused data when IPv6 is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
MAntoniak committed Feb 11, 2022
1 parent 5facab6 commit deb2c1f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
10 changes: 8 additions & 2 deletions lib/connect.c
Expand Up @@ -257,6 +257,9 @@ static CURLcode bindlocal(struct Curl_easy *data,
#ifdef IP_BIND_ADDRESS_NO_PORT
int on = 1;
#endif
#ifndef ENABLE_IPV6
(void)scope;
#endif

/*************************************************************
* Select device to bind socket to
Expand Down Expand Up @@ -314,8 +317,11 @@ static CURLcode bindlocal(struct Curl_easy *data,
}
#endif

switch(Curl_if2ip(af, scope, conn->scope_id, dev,
myhost, sizeof(myhost))) {
switch(Curl_if2ip(af,
#ifdef ENABLE_IPV6
scope, conn->scope_id,
#endif
dev, myhost, sizeof(myhost))) {
case IF2IP_NOT_FOUND:
if(is_interface) {
/* Do not fall back to treating it as a host name */
Expand Down
5 changes: 4 additions & 1 deletion lib/ftp.c
Expand Up @@ -1029,8 +1029,11 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data,
if(*addr != '\0') {
/* attempt to get the address of the given interface name */
switch(Curl_if2ip(conn->ip_addr->ai_family,
#ifdef ENABLE_IPV6
Curl_ipv6_scope(conn->ip_addr->ai_addr),
conn->scope_id, addr, hbuf, sizeof(hbuf))) {
conn->scope_id,
#endif
addr, hbuf, sizeof(hbuf))) {
case IF2IP_NOT_FOUND:
/* not an interface, use the given string as host name instead */
host = addr;
Expand Down
36 changes: 24 additions & 12 deletions lib/if2ip.c
Expand Up @@ -92,19 +92,19 @@ unsigned int Curl_ipv6_scope(const struct sockaddr *sa)

#if defined(HAVE_GETIFADDRS)

if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
unsigned int local_scope_id, const char *interf,
if2ip_result_t Curl_if2ip(int af,
#ifdef ENABLE_IPV6
unsigned int remote_scope,
unsigned int local_scope_id,
#endif
const char *interf,
char *buf, int buf_size)
{
struct ifaddrs *iface, *head;
if2ip_result_t res = IF2IP_NOT_FOUND;

#ifndef ENABLE_IPV6
(void) remote_scope;
#endif

#if !defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) || \
!defined(ENABLE_IPV6)
#if defined(ENABLE_IPV6) && \
!defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
(void) local_scope_id;
#endif

Expand Down Expand Up @@ -177,8 +177,12 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,

#elif defined(HAVE_IOCTL_SIOCGIFADDR)

if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
unsigned int local_scope_id, const char *interf,
if2ip_result_t Curl_if2ip(int af,
#ifdef ENABLE_IPV6
unsigned int remote_scope,
unsigned int local_scope_id,
#endif
const char *interf,
char *buf, int buf_size)
{
struct ifreq req;
Expand All @@ -188,8 +192,10 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
size_t len;
const char *r;

#ifdef ENABLE_IPV6
(void)remote_scope;
(void)local_scope_id;
#endif

if(!interf || (af != AF_INET))
return IF2IP_NOT_FOUND;
Expand Down Expand Up @@ -226,13 +232,19 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,

#else

if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
unsigned int local_scope_id, const char *interf,
if2ip_result_t Curl_if2ip(int af,
#ifdef ENABLE_IPV6
unsigned int remote_scope,
unsigned int local_scope_id,
#endif
const char *interf,
char *buf, int buf_size)
{
(void) af;
#ifdef ENABLE_IPV6
(void) remote_scope;
(void) local_scope_id;
#endif
(void) interf;
(void) buf;
(void) buf_size;
Expand Down
8 changes: 6 additions & 2 deletions lib/if2ip.h
Expand Up @@ -42,8 +42,12 @@ typedef enum {
IF2IP_FOUND = 2 /* The address has been stored in "buf" */
} if2ip_result_t;

if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
unsigned int local_scope_id, const char *interf,
if2ip_result_t Curl_if2ip(int af,
#ifdef ENABLE_IPV6
unsigned int remote_scope,
unsigned int local_scope_id,
#endif
const char *interf,
char *buf, int buf_size);

#ifdef __INTERIX
Expand Down
4 changes: 4 additions & 0 deletions lib/setopt.c
Expand Up @@ -155,7 +155,9 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
char *argptr;
CURLcode result = CURLE_OK;
long arg;
#ifdef ENABLE_IPV6
unsigned long uarg;
#endif
curl_off_t bigsize;

switch(option) {
Expand Down Expand Up @@ -2533,6 +2535,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
break;
#endif

#ifdef ENABLE_IPV6
case CURLOPT_ADDRESS_SCOPE:
/*
* Use this scope id when using IPv6
Expand All @@ -2546,6 +2549,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
#endif
data->set.scope_id = (unsigned int)uarg;
break;
#endif

case CURLOPT_PROTOCOLS:
/* set the bitmask for the protocols that are allowed to be used for the
Expand Down
2 changes: 2 additions & 0 deletions lib/url.c
Expand Up @@ -2109,9 +2109,11 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
return CURLE_OUT_OF_MEMORY;
conn->host.name = conn->host.rawalloc;

#ifdef ENABLE_IPV6
if(data->set.scope_id)
/* Override any scope that was set above. */
conn->scope_id = data->set.scope_id;
#endif

return CURLE_OK;
}
Expand Down
5 changes: 4 additions & 1 deletion lib/urldata.h
Expand Up @@ -940,8 +940,9 @@ struct connectdata {
cache entry remains locked. It gets unlocked in multi_done() */
struct Curl_addrinfo *ip_addr;
struct Curl_addrinfo *tempaddr[2]; /* for happy eyeballs */

#ifdef ENABLE_IPV6
unsigned int scope_id; /* Scope id for IPv6 */
#endif

enum {
TRNSPRT_TCP = 3,
Expand Down Expand Up @@ -1743,7 +1744,9 @@ struct UserDefined {
long ssh_auth_types; /* allowed SSH auth types */
char *str[STRING_LAST]; /* array of strings, pointing to allocated memory */
struct curl_blob *blobs[BLOB_LAST];
#ifdef ENABLE_IPV6
unsigned int scope_id; /* Scope id for IPv6 */
#endif
long allowed_protocols;
long redir_protocols;
long mime_options; /* Mime option flags. */
Expand Down

0 comments on commit deb2c1f

Please sign in to comment.