landing NSPR portion of patch for bug 239358 "DNS: Reverse lookups are degrading performance"

patch by lorenzo@colitti.com, r=wtc, sr=darin
This commit is contained in:
darin%meer.net 2004-08-30 23:31:36 +00:00
Родитель 3f6e250ea9
Коммит 7ce6cc17ec
2 изменённых файлов: 22 добавлений и 11 удалений

Просмотреть файл

@ -137,10 +137,11 @@ NSPR_API(PRStatus) PR_GetHostByName(
***********************************************************************/
#define PR_AI_ALL 0x08
#define PR_AI_V4MAPPED 0x10
#define PR_AI_ADDRCONFIG 0x20
#define PR_AI_DEFAULT (PR_AI_V4MAPPED | PR_AI_ADDRCONFIG)
#define PR_AI_ALL 0x08
#define PR_AI_V4MAPPED 0x10
#define PR_AI_ADDRCONFIG 0x20
#define PR_AI_NOCANONNAME 0x8000
#define PR_AI_DEFAULT (PR_AI_V4MAPPED | PR_AI_ADDRCONFIG)
NSPR_API(PRStatus) PR_GetIPNodeByName(
const char *hostname,
@ -396,8 +397,11 @@ NSPR_API(PRStatus) PR_GetProtoByNumber(
**
** INPUTS:
** char *hostname Character string defining the host name of interest
** PRUint16 af Must be PR_AF_UNSPEC
** PRIntn flags Must be PR_AI_ADDRCONFIG
** PRUint16 af May be PR_AF_UNSPEC or PR_AF_INET.
** PRIntn flags May be either PR_AI_ADDRCONFIG or
** PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME. Include
** PR_AI_NOCANONNAME to suppress the determination of
** the canonical name corresponding to hostname.
** RETURN:
** PRAddrInfo* Handle to a data structure containing the results
** of the host lookup. Use PR_EnumerateAddrInfo to

Просмотреть файл

@ -2031,6 +2031,7 @@ _pr_find_getaddrinfo(void)
typedef struct PRAddrInfoFB {
char buf[PR_NETDB_BUF_SIZE];
PRHostEnt hostent;
PRBool has_cname;
} PRAddrInfoFB;
static PRAddrInfo *
@ -2051,6 +2052,8 @@ pr_GetAddrInfoByNameFB(const char *hostname,
PR_Free(ai);
return NULL;
}
ai->has_cname = !(flags & PR_AI_NOCANONNAME);
return (PRAddrInfo *) ai;
}
@ -2059,7 +2062,8 @@ PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char *hostname,
PRIntn flags)
{
/* restrict input to supported values */
if ((af != PR_AF_INET && af != PR_AF_UNSPEC) || flags != PR_AI_ADDRCONFIG) {
if ((af != PR_AF_INET && af != PR_AF_UNSPEC) ||
(flags & ~ PR_AI_NOCANONNAME) != PR_AI_ADDRCONFIG) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@ -2085,7 +2089,7 @@ PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char *hostname,
*/
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_flags = (flags & PR_AI_NOCANONNAME) ? 0: AI_CANONNAME;
hints.ai_family = (af == PR_AF_INET) ? AF_INET : AF_UNSPEC;
/*
@ -2172,11 +2176,14 @@ PR_IMPLEMENT(const char *) PR_GetCanonNameFromAddrInfo(const PRAddrInfo *ai)
{
#if defined(_PR_HAVE_GETADDRINFO)
#if defined(_PR_INET6_PROBE)
if (!_pr_ipv6_is_present)
return ((const PRAddrInfoFB *) ai)->hostent.h_name;
if (!_pr_ipv6_is_present) {
const PRAddrInfoFB *fb = (const PRAddrInfoFB *) ai;
return fb->has_cname ? fb->hostent.h_name : NULL;
}
#endif
return ((const PRADDRINFO *) ai)->ai_canonname;
#else
return ((const PRAddrInfoFB *) ai)->hostent.h_name;
const PRAddrInfoFB *fb = (const PRAddrInfoFB *) ai;
return fb->has_cname ? fb->hostent.h_name : NULL;
#endif
}