ip_quadruple/proxy: make port uint16_t

Make `port` member in these struct of type `uint16_t`.

add `uint8_t transport` to `struct ip_quadruple

Define TRNSPRT_NONE as 0. By assigning a valid transport only on a
successful connection, it is clear when the ip_quadruple members are
valid. Also, for transports not involving ports, the getinfos for
`CURLINFO_PRIMARY_PORT` and `CURLINFO_LOCAL_PORT` will now always return
-1.

Make all `transport` members and parameters of type `uint8_t`.

Document the return value of `CURLINFO_LOCAL_PORT` and
`CURLINFO_PRIMARY_PORT` in this regard. Add tests that writeout stats
report ports correctly.

Closes #19708
This commit is contained in:
Stefan Eissing 2025-11-26 14:05:46 +01:00 committed by Daniel Stenberg
parent feea968512
commit c4f29cc508
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
20 changed files with 104 additions and 80 deletions

View file

@ -2171,7 +2171,6 @@ static CURLcode parse_proxy(struct Curl_easy *data,
long proxytype)
{
char *portptr = NULL;
int port = -1;
char *proxyuser = NULL;
char *proxypasswd = NULL;
char *host = NULL;
@ -2293,24 +2292,23 @@ static CURLcode parse_proxy(struct Curl_easy *data,
if(portptr) {
curl_off_t num;
const char *p = portptr;
if(!curlx_str_number(&p, &num, 0xffff))
port = (int)num;
if(!curlx_str_number(&p, &num, UINT16_MAX))
proxyinfo->port = (uint16_t)num;
/* Should we not error out when the port number is invalid? */
free(portptr);
}
else {
if(data->set.proxyport)
/* None given in the proxy string, then get the default one if it is
given */
port = (int)data->set.proxyport;
proxyinfo->port = data->set.proxyport;
else {
if(IS_HTTPS_PROXY(proxytype))
port = CURL_DEFAULT_HTTPS_PROXY_PORT;
proxyinfo->port = CURL_DEFAULT_HTTPS_PROXY_PORT;
else
port = CURL_DEFAULT_PROXY_PORT;
proxyinfo->port = CURL_DEFAULT_PROXY_PORT;
}
}
if(port >= 0)
proxyinfo->port = port;
/* now, clone the proxy hostname */
uc = curl_url_get(uhp, CURLUPART_HOST, &host, CURLU_URLDECODE);