测试WIFI先扫描SID

This commit is contained in:
2024-11-11 17:37:06 +08:00
parent d85cdffa6f
commit c976c93aa5
4 changed files with 94 additions and 20 deletions

View File

@@ -194,7 +194,21 @@ static TCP_CLIENT_T* tcp_client_init(void) {
DEBUG_printf("failed to allocate state\n"); // 分配失败
return NULL;
}
ip4addr_aton(TEST_TCP_SERVER_IP, &state->remote_addr); // 解析服务器IP地址
// 如果 TEST_TCP_SERVER_IP 是 IP 地址,直接解析为 IP 地址
if (ip4addr_aton(TEST_TCP_SERVER_IP, &state->remote_addr) == 0) {
// 如果解析失败,尝试作为域名解析
DEBUG_printf("Failed to parse IP address, trying DNS resolution\n");
err_t err = dns_gethostbyname(TEST_TCP_SERVER_IP, &state->remote_addr, NULL, NULL);
if (err != ERR_OK) {
DEBUG_printf("DNS resolution failed\n");
free(state);
return NULL;
}
}
return state;
}