curl / curl

A command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS and WSS. libcurl offers a myriad of powerful features
https://curl.se/
Other
34.74k stars 6.24k forks source link

CURLOPT_RESOLVE: support "*" for port number #13984

Closed bagder closed 6 days ago

bagder commented 6 days ago

Allow resolves for a hostname independent of port number, to a fixed address. Resolves to a fixed port number have priority.

Also works if the hostname itself is using "*" to catch all hostnames.

A key to this change is to no longer use the port number from the DNS struct stored in the cache when connecting since it is not the correct one when a wildcard port is used for CURLOPT_RESOLVE.

Removes TODO item 1.8

Verified by test 1488 and 1489

bagder commented 6 days ago

@icing I'm not too happy with how I get the port number in Curl_cf_tcp_create, maybe you have a better idea there? It needs to get the secondary port number for FTP and otherwise pass on the primary.

icing commented 6 days ago

@icing I'm not too happy with how I get the port number in Curl_cf_tcp_create, maybe you have a better idea there? It needs to get the secondary port number for FTP and otherwise pass on the primary.

Yeah, this looks a bit ugly. As I understand it, the Curl_resolve() always gave a Curl_dns_entry that contained a Curl_addrinfo that carried the ip address and port. And that port was always the port that was asked for when resolving.

Now we have a wildport(?) Curl_dns_entry with port -1 and the information about the port we want to resolve is lost when that is passed on. That's why you added the extra port parameter to overwrite that later when the actual socket is being created for addr.

I think it would be better if hostip.c's fetch_addr() returns a copy of a wildport dns entry that carries the correct port in its address infos.

bagder commented 6 days ago

I think it would be better if hostip.c's fetch_addr() returns a copy of a wildport dns entry that carries the correct port in its address infos.

Right, I was pondering on that as well. I'll try that, even if that means having to copy the buffer there instead of just referencing it.

Thanks!

bagder commented 6 days ago

As was pointed out to me, this can already be accomplished with --connect-to:

curl --connect-to ::127.0.0.1: example.com

Maybe I could still support this syntax on the cmdline, and convert it to this --connect-to version under the hood. Also saves us from having to change libcurl.

bagder commented 6 days ago

Or maybe I just document it better...

bagder commented 6 days ago

13989

bagder commented 6 days ago

Let's ditch this PR since we can accomplish this already!