mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-09 02:40:08 +00:00
gaih_inet: make gethosts into a function
The macro is quite a pain to debug, so make gethosts into a function to
make it easier to maintain.
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit cfa3bd48cb
)
This commit is contained in:
parent
9098deb96a
commit
8b70d97b08
@ -268,63 +268,54 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, int family,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define gethosts(_family) \
|
static int
|
||||||
{ \
|
gethosts (nss_gethostbyname3_r fct, int family, const char *name,
|
||||||
struct hostent th; \
|
const struct addrinfo *req, struct scratch_buffer *tmpbuf,
|
||||||
char *localcanon = NULL; \
|
struct gaih_result *res, enum nss_status *statusp, int *no_datap)
|
||||||
no_data = 0; \
|
{
|
||||||
while (1) \
|
struct hostent th;
|
||||||
{ \
|
char *localcanon = NULL;
|
||||||
status = DL_CALL_FCT (fct, (name, _family, &th, \
|
enum nss_status status;
|
||||||
tmpbuf->data, tmpbuf->length, \
|
|
||||||
&errno, &h_errno, NULL, &localcanon)); \
|
|
||||||
if (status != NSS_STATUS_TRYAGAIN || h_errno != NETDB_INTERNAL \
|
|
||||||
|| errno != ERANGE) \
|
|
||||||
break; \
|
|
||||||
if (!scratch_buffer_grow (tmpbuf)) \
|
|
||||||
{ \
|
|
||||||
__resolv_context_put (res_ctx); \
|
|
||||||
result = -EAI_MEMORY; \
|
|
||||||
goto out; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
if (status == NSS_STATUS_NOTFOUND \
|
|
||||||
|| status == NSS_STATUS_TRYAGAIN || status == NSS_STATUS_UNAVAIL) \
|
|
||||||
{ \
|
|
||||||
if (h_errno == NETDB_INTERNAL) \
|
|
||||||
{ \
|
|
||||||
__resolv_context_put (res_ctx); \
|
|
||||||
result = -EAI_SYSTEM; \
|
|
||||||
goto out; \
|
|
||||||
} \
|
|
||||||
if (h_errno == TRY_AGAIN) \
|
|
||||||
no_data = EAI_AGAIN; \
|
|
||||||
else \
|
|
||||||
no_data = h_errno == NO_DATA; \
|
|
||||||
} \
|
|
||||||
else if (status == NSS_STATUS_SUCCESS) \
|
|
||||||
{ \
|
|
||||||
if (!convert_hostent_to_gaih_addrtuple (req, _family, &th, res)) \
|
|
||||||
{ \
|
|
||||||
__resolv_context_put (res_ctx); \
|
|
||||||
result = -EAI_SYSTEM; \
|
|
||||||
goto out; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
if (localcanon != NULL && res->canon == NULL) \
|
|
||||||
{ \
|
|
||||||
char *canonbuf = __strdup (localcanon); \
|
|
||||||
if (canonbuf == NULL) \
|
|
||||||
{ \
|
|
||||||
__resolv_context_put (res_ctx); \
|
|
||||||
result = -EAI_SYSTEM; \
|
|
||||||
goto out; \
|
|
||||||
} \
|
|
||||||
res->canon = canonbuf; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
*no_datap = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
*statusp = status = DL_CALL_FCT (fct, (name, family, &th,
|
||||||
|
tmpbuf->data, tmpbuf->length,
|
||||||
|
&errno, &h_errno, NULL,
|
||||||
|
&localcanon));
|
||||||
|
if (status != NSS_STATUS_TRYAGAIN || h_errno != NETDB_INTERNAL
|
||||||
|
|| errno != ERANGE)
|
||||||
|
break;
|
||||||
|
if (!scratch_buffer_grow (tmpbuf))
|
||||||
|
return -EAI_MEMORY;
|
||||||
|
}
|
||||||
|
if (status == NSS_STATUS_NOTFOUND
|
||||||
|
|| status == NSS_STATUS_TRYAGAIN || status == NSS_STATUS_UNAVAIL)
|
||||||
|
{
|
||||||
|
if (h_errno == NETDB_INTERNAL)
|
||||||
|
return -EAI_SYSTEM;
|
||||||
|
if (h_errno == TRY_AGAIN)
|
||||||
|
*no_datap = EAI_AGAIN;
|
||||||
|
else
|
||||||
|
*no_datap = h_errno == NO_DATA;
|
||||||
|
}
|
||||||
|
else if (status == NSS_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
if (!convert_hostent_to_gaih_addrtuple (req, family, &th, res))
|
||||||
|
return -EAI_SYSTEM;
|
||||||
|
|
||||||
|
if (localcanon != NULL && res->canon == NULL)
|
||||||
|
{
|
||||||
|
char *canonbuf = __strdup (localcanon);
|
||||||
|
if (canonbuf == NULL)
|
||||||
|
return -EAI_SYSTEM;
|
||||||
|
res->canon = canonbuf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* This function is called if a canonical name is requested, but if
|
/* This function is called if a canonical name is requested, but if
|
||||||
the service function did not provide it. It tries to obtain the
|
the service function did not provide it. It tries to obtain the
|
||||||
@ -741,7 +732,12 @@ get_nss_addresses (const char *name, const struct addrinfo *req,
|
|||||||
if (req->ai_family == AF_INET6
|
if (req->ai_family == AF_INET6
|
||||||
|| req->ai_family == AF_UNSPEC)
|
|| req->ai_family == AF_UNSPEC)
|
||||||
{
|
{
|
||||||
gethosts (AF_INET6);
|
if ((result = gethosts (fct, AF_INET6, name, req, tmpbuf,
|
||||||
|
res, &status, &no_data)) != 0)
|
||||||
|
{
|
||||||
|
__resolv_context_put (res_ctx);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
no_inet6_data = no_data;
|
no_inet6_data = no_data;
|
||||||
inet6_status = status;
|
inet6_status = status;
|
||||||
}
|
}
|
||||||
@ -753,7 +749,12 @@ get_nss_addresses (const char *name, const struct addrinfo *req,
|
|||||||
know we are not going to need them. */
|
know we are not going to need them. */
|
||||||
&& ((req->ai_flags & AI_ALL) || !res->got_ipv6)))
|
&& ((req->ai_flags & AI_ALL) || !res->got_ipv6)))
|
||||||
{
|
{
|
||||||
gethosts (AF_INET);
|
if ((result = gethosts (fct, AF_INET, name, req, tmpbuf,
|
||||||
|
res, &status, &no_data)) != 0)
|
||||||
|
{
|
||||||
|
__resolv_context_put (res_ctx);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (req->ai_family == AF_INET)
|
if (req->ai_family == AF_INET)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user