netdb:fixed addrtype and length in gethostbyname

Fix for the h_length field of struct hostent returned by gethostbyname() functions was returning 24 bytes instead of 4 and h_addrtype was returning AF_INET even for IPv6 address.

Closes https://github.com/espressif/esp-lwip/issues/50
This commit is contained in:
Abhik Roy
2022-12-13 15:07:19 +05:30
parent 280c3d61d9
commit aee6b3ed0c
+4 -4
View File
@@ -113,8 +113,8 @@ lwip_gethostbyname(const char *name)
s_hostent.h_name = s_hostname;
s_aliases = NULL;
s_hostent.h_aliases = &s_aliases;
s_hostent.h_addrtype = AF_INET;
s_hostent.h_length = sizeof(ip_addr_t);
s_hostent.h_addrtype = (IPADDR_TYPE_V4 == IP_GET_TYPE(&addr)? AF_INET : AF_INET6);
s_hostent.h_length = IP_ADDR_RAW_SIZE(addr);
s_hostent.h_addr_list = (char **)&s_phostent_addr;
#if DNS_DEBUG
@@ -213,8 +213,8 @@ lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
h->aliases = NULL;
ret->h_name = hostname;
ret->h_aliases = &h->aliases;
ret->h_addrtype = AF_INET;
ret->h_length = sizeof(ip_addr_t);
ret->h_addrtype = (IPADDR_TYPE_V4 == IP_GET_TYPE(&h->addr)? AF_INET : AF_INET6);
ret->h_length = IP_ADDR_RAW_SIZE(h->addr);
ret->h_addr_list = (char **)&h->addr_list;
/* set result != NULL */