Subject: Re: Megatools over IPv6 - bug report
From: Ondřej Jirman
Date: Thu, 5 Nov 2020 13:56:48 +0100
Hi,

On Thu, Nov 05, 2020 at 05:51:50PM +0800, bert@ev6.net wrote:
> Hi,
> 
> I am attempting to use megadl on an IPv6-only host, this should work as mega.nz is fully IPv6 enabled.
> 
> It first tries to connect to g.api.mega.co.nz, this host does have IPv6 addresses:

There were some issues with it in the past, so it was disabled in the code.
I guess it's time to enable it again.

thnak you and regards,
	o.

> # host g.api.mega.co.nz.
> g.api.mega.co.nz is an alias for lu.api.mega.co.nz.
> lu.api.mega.co.nz has address 66.203.125.13
> lu.api.mega.co.nz has address 66.203.125.11
> lu.api.mega.co.nz has address 66.203.125.14
> lu.api.mega.co.nz has address 66.203.125.12
> lu.api.mega.co.nz has address 66.203.125.15
> lu.api.mega.co.nz has IPv6 address 2a0b:e46:1:100::14
> lu.api.mega.co.nz has IPv6 address 2a0b:e46:1:100::12
> lu.api.mega.co.nz has IPv6 address 2a0b:e46:1:100::13
> lu.api.mega.co.nz has IPv6 address 2a0b:e46:1:100::11
> lu.api.mega.co.nz has IPv6 address 2a0b:e46:1:100::15
> However, the tool only attempts to connect to the legacy IPv4 addresses when run with --debug=http:
> 
> *   Trying 66.203.125.13:443...
> * Immediate connect fail for 66.203.125.13: Network is unreachable
> *   Trying 66.203.125.11:443...
> * Immediate connect fail for 66.203.125.11: Network is unreachable
> *   Trying 66.203.125.14:443...
> * Immediate connect fail for 66.203.125.14: Network is unreachable
> *   Trying 66.203.125.12:443...
> * Immediate connect fail for 66.203.125.12: Network is unreachable
> *   Trying 66.203.125.15:443...
> * Immediate connect fail for 66.203.125.15: Network is unreachable
> * Closing connection 0
> Manually accessing mega.nz with curl works as expected over IPv6.
> 
> This appears to be caused by the following line in http.c which forces libcurl to only resolve legacy ipv4 addresses:
> 
> ./lib/http.c:	curl_easy_setopt(h->curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
> 
> by changing it back to the default value, it all works fine:
> 
> ./lib/http.c:	curl_easy_setopt(h->curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);
> 
>