mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
Tweak the existing special case for AIX in pg_getaddrinfo_all() to handle
yet another failure case in AIX's getaddrinfo(). Per report and patch by Andrew Chernow.
This commit is contained in:
parent
4d65d2872b
commit
006b9e7a92
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.43 2009/01/01 17:23:42 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.44 2009/01/23 19:58:06 tgl Exp $
|
||||||
*
|
*
|
||||||
* This file and the IPV6 implementation were initially provided by
|
* This file and the IPV6 implementation were initially provided by
|
||||||
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
|
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
|
||||||
@ -74,36 +74,46 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
|
|||||||
return getaddrinfo_unix(servname, hintp, result);
|
return getaddrinfo_unix(servname, hintp, result);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _AIX
|
||||||
/* NULL has special meaning to getaddrinfo(). */
|
/* NULL has special meaning to getaddrinfo(). */
|
||||||
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
|
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
|
||||||
servname, hintp, result);
|
servname, hintp, result);
|
||||||
|
|
||||||
#ifdef _AIX
|
#else /* _AIX */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It seems some versions of AIX's getaddrinfo don't reliably zero
|
* Various versions of AIX have various bugs in getaddrinfo()'s handling
|
||||||
* sin_port when servname is NULL, so clean up after it.
|
* of the servname parameter, including failing entirely if it's not NULL
|
||||||
|
* and failing to zero sin_port when it is NULL :-(. Avoid these by
|
||||||
|
* always passing NULL and handling the port number for ourselves.
|
||||||
*/
|
*/
|
||||||
if (servname == NULL && rc == 0)
|
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
|
||||||
|
NULL, hintp, result);
|
||||||
|
|
||||||
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
struct addrinfo *addr;
|
struct addrinfo *addr;
|
||||||
|
unsigned short port = 0;
|
||||||
|
|
||||||
|
if (servname && *servname)
|
||||||
|
port = atoi(servname);
|
||||||
|
|
||||||
for (addr = *result; addr; addr = addr->ai_next)
|
for (addr = *result; addr; addr = addr->ai_next)
|
||||||
{
|
{
|
||||||
switch (addr->ai_family)
|
switch (addr->ai_family)
|
||||||
{
|
{
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
((struct sockaddr_in *) addr->ai_addr)->sin_port = htons(0);
|
((struct sockaddr_in *) addr->ai_addr)->sin_port = htons(port);
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
((struct sockaddr_in6 *) addr->ai_addr)->sin6_port = htons(0);
|
((struct sockaddr_in6 *) addr->ai_addr)->sin6_port = htons(port);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* _AIX */
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user