handle domain with trailing dot

Closes: #7032
This commit is contained in:
Jeff Epler 2022-11-30 09:29:05 -06:00
parent 4af95f1cb1
commit 286efc18fc
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE

View File

@ -45,6 +45,16 @@ void common_hal_socketpool_socketpool_construct(socketpool_socketpool_obj_t *sel
mp_obj_t common_hal_socketpool_socketpool_gethostbyname(socketpool_socketpool_obj_t *self,
const char *host) {
// As of 2022, the version of lwip in esp-idf does not handle the
// trailing-dot syntax of domain names, so emulate it.
// Remove this once https://github.com/espressif/esp-idf/issues/10013 has
// been implemented
size_t strlen_host = strlen(host);
if (strlen_host && host[strlen_host - 1] == '.') {
mp_obj_t nodot = mp_obj_new_str(host, strlen_host - 1);
host = mp_obj_str_get_str(nodot);
}
const struct addrinfo hints = {
.ai_family = AF_INET,
.ai_socktype = SOCK_STREAM,