public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/siddhesh/gai-cleanup2] gaih_inet: Split local lookup into its own function
@ 2022-03-01 2:41 Siddhesh Poyarekar
0 siblings, 0 replies; only message in thread
From: Siddhesh Poyarekar @ 2022-03-01 2:41 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0a1298f71cefd620fea0ea600a519288c060d298
commit 0a1298f71cefd620fea0ea600a519288c060d298
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Mon Feb 28 23:05:51 2022 +0530
gaih_inet: Split local lookup into its own function
Drop the local AT variable so that everything is now in RES.
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diff:
---
sysdeps/posix/getaddrinfo.c | 78 ++++++++++++++++++++++-----------------------
1 file changed, 39 insertions(+), 39 deletions(-)
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 3dd2f8cff7..89bca7795a 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -1053,6 +1053,37 @@ free_and_return:
return result;
}
+static void
+get_local_addresses (const struct addrinfo *req,
+ struct gaih_lookup_result *res)
+{
+ struct gaih_addrtuple *at = res->at;
+ struct gaih_addrtuple *atr = res->at;
+
+ memset (at, '\0', sizeof (struct gaih_addrtuple));
+
+ if (req->ai_family == AF_UNSPEC)
+ {
+ at->next = __alloca (sizeof (struct gaih_addrtuple));
+ memset (at->next, '\0', sizeof (struct gaih_addrtuple));
+ }
+
+ if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
+ {
+ at->family = AF_INET6;
+ if ((req->ai_flags & AI_PASSIVE) == 0)
+ memcpy (at->addr, &in6addr_loopback, sizeof (struct in6_addr));
+ atr = at->next;
+ }
+
+ if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
+ {
+ atr->family = AF_INET;
+ if ((req->ai_flags & AI_PASSIVE) == 0)
+ atr->addr[0] = htonl (INADDR_LOOPBACK);
+ }
+}
+
static int
process_canonname (const struct addrinfo *req, const char *orig_name,
char **canonp)
@@ -1093,7 +1124,6 @@ gaih_inet (const char *name, const struct gaih_service *service,
struct gaih_servtuple st[sizeof (gaih_inet_typeproto)
/ sizeof (struct gaih_typeproto)] = {0};
- struct gaih_addrtuple *at = NULL;
char *canon = NULL;
const char *orig_name = name;
@@ -1129,8 +1159,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
goto free_and_return;
else if (res.at != NULL)
{
- at = res.at;
- canon = at->name;
+ canon = res.at->name;
goto process_list;
}
@@ -1142,10 +1171,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
if ((result = simple_gethostbyname (name, req, tmpbuf, &res)) != 0)
goto free_and_return;
else if (res.at != NULL)
- {
- at = res.at;
- goto process_list;
- }
+ goto process_list;
}
#ifdef USE_NSCD
@@ -1153,8 +1179,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
goto free_and_return;
else if (res.at != NULL)
{
- at = res.at;
- canon = at->name;
+ canon = res.at->name;
goto process_list;
}
#endif
@@ -1162,12 +1187,9 @@ gaih_inet (const char *name, const struct gaih_service *service,
if ((result = get_nss_addresses (name, req, tmpbuf, &res)) != 0)
goto free_and_return;
else if (res.at != NULL)
- {
- at = res.at;
- canon = at->name;
- }
+ canon = res.at->name;
- if (at == NULL)
+ if (res.at == NULL)
{
result = -EAI_NONAME;
goto free_and_return;
@@ -1175,30 +1197,8 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
else
{
- struct gaih_addrtuple *atr;
- atr = at = alloca_account (sizeof (struct gaih_addrtuple), alloca_used);
- memset (at, '\0', sizeof (struct gaih_addrtuple));
-
- if (req->ai_family == AF_UNSPEC)
- {
- at->next = __alloca (sizeof (struct gaih_addrtuple));
- memset (at->next, '\0', sizeof (struct gaih_addrtuple));
- }
-
- if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
- {
- at->family = AF_INET6;
- if ((req->ai_flags & AI_PASSIVE) == 0)
- memcpy (at->addr, &in6addr_loopback, sizeof (struct in6_addr));
- atr = at->next;
- }
-
- if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
- {
- atr->family = AF_INET;
- if ((req->ai_flags & AI_PASSIVE) == 0)
- atr->addr[0] = htonl (INADDR_LOOPBACK);
- }
+ res.at = alloca_account (sizeof (struct gaih_addrtuple), alloca_used);
+ get_local_addresses (req, &res);
}
process_list:
@@ -1212,7 +1212,7 @@ process_list:
/* Buffer is the size of an unformatted IPv6 address in printable
format. */
- for (struct gaih_addrtuple *at2 = at; at2 != NULL; at2 = at2->next)
+ for (struct gaih_addrtuple *at2 = res.at; at2 != NULL; at2 = at2->next)
{
family = at2->family;
if (family == AF_INET6)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-01 2:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01 2:41 [glibc/siddhesh/gai-cleanup2] gaih_inet: Split local lookup into its own function Siddhesh Poyarekar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).