summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarin%meer.net <devnull@localhost>2004-08-30 23:29:52 +0000
committerdarin%meer.net <devnull@localhost>2004-08-30 23:29:52 +0000
commitcfc362a24bdc91af4cb320f4f075e72f8e0bd8b0 (patch)
treea97ec596ce783f44ffd5ded0887b4ef31fc6ee44
parent0e7595af744272d75db0e9c2a395c018d8549a4f (diff)
downloadnspr-hg-cfc362a24bdc91af4cb320f4f075e72f8e0bd8b0.tar.gz
landing NSPR portion of patch for bug 239358 "DNS: Reverse lookups are degrading performance"
patch by lorenzo@colitti.com, r=wtc, sr=darin
-rw-r--r--pr/include/prnetdb.h16
-rw-r--r--pr/src/misc/prnetdb.c17
2 files changed, 22 insertions, 11 deletions
diff --git a/pr/include/prnetdb.h b/pr/include/prnetdb.h
index cdd00f57..685efbbc 100644
--- a/pr/include/prnetdb.h
+++ b/pr/include/prnetdb.h
@@ -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
diff --git a/pr/src/misc/prnetdb.c b/pr/src/misc/prnetdb.c
index 3dfdb385..c3b7cdd5 100644
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -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
}