找到webclient-v2.1.2 文件夹
大约 164行
//修改如下
static int webclient_resolve_address(struct webclient_session *session, struct addrinfo **res,
const char *url, const char **request)
{
int rc = WEBCLIENT_OK;
char *ptr;
char port_str[6] = "80"; /* default port of 80(http) */
const char *port_ptr;
const char *path_ptr;
const char *host_addr = 0;
int url_len, host_addr_len = 0;
RT_ASSERT(res);
RT_ASSERT(request);
url_len = rt_strlen(url);
/* strip protocol(http or https) */
if (strncmp(url, "http://", 7) == 0)
{
host_addr = url + 7;
}
else if (strncmp(url, "https://", 8) == 0)
{
rt_strncpy(port_str, "443", 4);
host_addr = url + 8;
}
else
{
rc = -WEBCLIENT_ERROR;
goto __exit;
}
/* ipv6 address */
if (host_addr[0] == '[')
{
host_addr += 1;
ptr = rt_strstr(host_addr, "]");
if (!ptr)
{
rc = -WEBCLIENT_ERROR;
goto __exit;
}
host_addr_len = ptr - host_addr;
}
path_ptr = rt_strstr(host_addr, "/");
*request = path_ptr ? path_ptr : "/";
/* resolve port */
port_ptr = rt_strstr(host_addr + host_addr_len, ":");
int port_len;
if (port_ptr && path_ptr && (port_ptr < path_ptr))
{
port_len = path_ptr - port_ptr - 1;
rt_strncpy(port_str, port_ptr + 1, port_len);
port_str[port_len] = '\0';
}
//2020 11 6 cbq add 2022-2-11 19:10:35 lzf add new len判断
//解决端口解析问题
if (port_ptr)
{
if ((port_len < 6) && (atoi(&port_ptr[1]) > 0))
{
}
else
{
port_ptr = RT_NULL;
}
}
if (port_ptr && (!path_ptr))
{
strcpy(port_str, port_ptr + 1);
}
/* ipv4 or domain. */
if (!host_addr_len)
{
if (port_ptr)
{
host_addr_len = port_ptr - host_addr;
}
else if (path_ptr)
{
host_addr_len = path_ptr - host_addr;
}
else
{
host_addr_len = strlen(host_addr);
}
}
if ((host_addr_len < 1) || (host_addr_len > url_len))
{
rc = -WEBCLIENT_ERROR;
goto __exit;
}
/* get host address ok. */
{
char *host_addr_new = web_malloc(host_addr_len + 1);
if (!host_addr_new)
{
rc = -WEBCLIENT_ERROR;
goto __exit;
}
memcpy(host_addr_new, host_addr, host_addr_len);
host_addr_new[host_addr_len] = '\0';
session->host = host_addr_new;
}
LOG_D("host address: %s , port: %s", session->host, port_str);
#ifdef WEBCLIENT_USING_MBED_TLS
if (session->tls_session)
{
session->tls_session->port = web_strdup(port_str);
session->tls_session->host = web_strdup(session->host);
if (session->tls_session->port == RT_NULL || session->tls_session->host == RT_NULL)
{
return -WEBCLIENT_NOMEM;
}
return rc;
}
#endif
/* resolve the host name. */
{
struct addrinfo hint;
int ret;
rt_memset(&hint, 0, sizeof(hint));
ret = getaddrinfo(session->host, port_str, &hint, res);
if (ret != 0)
{
LOG_E("getaddrinfo err: %d '%s'.", ret, session->host);
rc = -WEBCLIENT_ERROR;
goto __exit;
}
}
__exit:
if (rc != WEBCLIENT_OK)
{
if (session->host)
{
web_free(session->host);
session->host = RT_NULL;
}
if (*res)
{
freeaddrinfo(*res);
*res = RT_NULL;
}
}
return rc;
}