From 23035ca68dfc1d6554a1954269201e80cf68dae4 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Fri, 21 Aug 2015 18:33:03 -0600 Subject: [PATCH] [PATCH] gethostbyname(): correct returned address format when DNS is used. The hostent.h_addr_list should point to raw in_addr or in6_addr as defined in the standard. Original implementation used that for numeric addresses but for DNS lookup returned pointer to whole sockaddr_in or sockaddr_in6. getaddrinfo() should be preferred in a long term perspective. Return of complete addresses from the lookup would be better in such case but it requires significant changes anyway - multiple addresses support and most probably dynamic memory allocation which is bad for many RT applications. So gethostbyname() is sufficient for most applications now. Signed-off-by: Pavel Pisa --- ChangeLog | 3 +++ arch | 2 +- libc/netdb/lib_gethostbynamer.c | 10 ++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 577712b511..c6d94c3215 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10857,4 +10857,7 @@ * sched/wdog/wd_create.c: Correct a counting error in the number of available watchdog timers. When the number of free timers is low, the counter could be incremented below zero (2015-08-15). + * arch/arm/src/stm32: Add OTG support for STM32F44x. From David + Sidrane (2015-08-15). + diff --git a/arch b/arch index b2709988e6..e725e3d458 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit b2709988e66303b69358f7b7a910905a6a7ff888 +Subproject commit e725e3d458e77bb268ca3a02909c71c2e5751f24 diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index f9bd4af9f0..ff90bcbf76 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -236,6 +236,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, { FAR struct hostent_info_s *info; FAR char *ptr; + FAR void *addrdata; socklen_t addrlen; int addrtype; int namelen; @@ -280,6 +281,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); addrtype = AF_INET; + addrdata = &((FAR struct sockaddr_in *)ptr)->sin_addr; } #endif @@ -291,12 +293,13 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); addrtype = AF_INET6; + addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin_addr; } #endif /* Yes.. Return the address that we obtained from the DNS cache. */ - info->hi_addrlist[0] = ptr; + info->hi_addrlist[0] = addrdata; host->h_addr_list = info->hi_addrlist; host->h_addrtype = addrtype; host->h_length = addrlen; @@ -377,6 +380,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, { FAR struct hostent_info_s *info; FAR char *ptr; + FAR void *addrdata; socklen_t addrlen; int addrtype; int namelen; @@ -419,6 +423,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); addrtype = AF_INET; + addrdata = &((FAR struct sockaddr_in *)ptr)->sin_addr; } #endif @@ -430,12 +435,13 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, DEBUGASSERT(addrlen == sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); addrtype = AF_INET6; + addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin_addr; } #endif /* Yes.. Return the address that we obtained from the DNS name server. */ - info->hi_addrlist[0] = ptr; + info->hi_addrlist[0] = addrdata; host->h_addr_list = info->hi_addrlist; host->h_addrtype = addrtype; host->h_length = addrlen;