From 2be9bfa40a66b71db4c29aff82527a086bbd3257 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 9 Jul 2015 09:14:42 -0600 Subject: [PATCH] gethostbyname() should succeed for matches on host name aliases as well --- libc/net/lib_gethostbynamer.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libc/net/lib_gethostbynamer.c b/libc/net/lib_gethostbynamer.c index c1fe9ca8ea..39dcec5c17 100644 --- a/libc/net/lib_gethostbynamer.c +++ b/libc/net/lib_gethostbynamer.c @@ -301,6 +301,9 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host, /* We successfully read the entry */ nvdbg("Comparing %s to %s\n", name, host->h_name); + + /* Check for a host name match */ + if (strcmp(name, host->h_name) == 0) { /* We have a match */ @@ -308,6 +311,26 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host, fclose(stream); return OK; } + + /* For a match with any host alias */ + + if (host->h_aliases != NULL) + { + FAR char **alias; + + for (alias = host->h_aliases; *alias != NULL; alias++) + { + /* Check for a host alias match */ + + if (strcmp(name, *alias) == 0) + { + /* We have a match */ + + fclose(stream); + return OK; + } + } + } } } while (nread != 0);