From 4de3387eb2396043db436edf8c35a8c4f105abbf Mon Sep 17 00:00:00 2001 From: zhanghongyu Date: Wed, 11 Jan 2023 17:24:47 +0800 Subject: [PATCH] getaddrinfo: add AI_NUMERICHOST flag handle Signed-off-by: zhanghongyu --- libs/libc/netdb/lib_getaddrinfo.c | 4 +--- libs/libc/netdb/lib_gethostbyname2r.c | 2 +- libs/libc/netdb/lib_gethostentbynamer.c | 8 +++++++- libs/libc/netdb/lib_netdb.h | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/libc/netdb/lib_getaddrinfo.c b/libs/libc/netdb/lib_getaddrinfo.c index cc6b9f0571..2d5ae0f6c7 100644 --- a/libs/libc/netdb/lib_getaddrinfo.c +++ b/libs/libc/netdb/lib_getaddrinfo.c @@ -306,10 +306,8 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname, return EAI_MEMORY; } - /* REVISIT: no check for AI_NUMERICHOST flag. */ - gethostentbyname_r(hostname, &host, - hostbuffer, CONFIG_NETDB_BUFSIZE, &ret); + hostbuffer, CONFIG_NETDB_BUFSIZE, &ret, flags); if (ret != OK) { lib_free(hostbuffer); diff --git a/libs/libc/netdb/lib_gethostbyname2r.c b/libs/libc/netdb/lib_gethostbyname2r.c index a0e0ce3095..82f41dac79 100644 --- a/libs/libc/netdb/lib_gethostbyname2r.c +++ b/libs/libc/netdb/lib_gethostbyname2r.c @@ -83,7 +83,7 @@ int gethostbyname2_r(FAR const char *name, int type, *result = NULL; - ret = gethostentbyname_r(name, &tmp, buf, buflen, h_errnop); + ret = gethostentbyname_r(name, &tmp, buf, buflen, h_errnop, 0); if (ret == OK) { if (convert_hostent(&tmp, type, host)) diff --git a/libs/libc/netdb/lib_gethostentbynamer.c b/libs/libc/netdb/lib_gethostentbynamer.c index 8222ae830a..1b17d8ac84 100644 --- a/libs/libc/netdb/lib_gethostentbynamer.c +++ b/libs/libc/netdb/lib_gethostentbynamer.c @@ -716,7 +716,7 @@ errorout_with_herrnocode: int gethostentbyname_r(FAR const char *name, FAR struct hostent_s *host, FAR char *buf, - size_t buflen, FAR int *h_errnop) + size_t buflen, FAR int *h_errnop, int flags) { DEBUGASSERT(name != NULL && host != NULL && buf != NULL); @@ -735,6 +735,12 @@ int gethostentbyname_r(FAR const char *name, return OK; } + else if ((flags & AI_NUMERICHOST) != 0) + { + *h_errnop = EAI_NONAME; + + return ERROR; + } #ifdef CONFIG_NET_LOOPBACK /* Check for the local loopback host name */ diff --git a/libs/libc/netdb/lib_netdb.h b/libs/libc/netdb/lib_netdb.h index 8a43d0c11a..72dcf91ec4 100644 --- a/libs/libc/netdb/lib_netdb.h +++ b/libs/libc/netdb/lib_netdb.h @@ -113,7 +113,7 @@ ssize_t parse_hostfile(FAR FILE *stream, FAR struct hostent_s *host, int gethostentbyname_r(FAR const char *name, FAR struct hostent_s *host, FAR char *buf, - size_t buflen, FAR int *h_errnop); + size_t buflen, FAR int *h_errnop, int flags); #undef EXTERN #ifdef __cplusplus