Created
August 25, 2011 22:28
-
-
Save ry/1172182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 2a86ba26f70c1024cd7357fd73c48318ff624689 Mon Sep 17 00:00:00 2001 | |
From: Ryan Dahl <ry@tinyclouds.org> | |
Date: Thu, 25 Aug 2011 15:22:43 -0700 | |
Subject: [PATCH] Fix dns_uv.lookup order | |
--- | |
lib/dns_uv.js | 18 +++++++++++++++++- | |
1 files changed, 17 insertions(+), 1 deletions(-) | |
diff --git a/lib/dns_uv.js b/lib/dns_uv.js | |
index cc6a1b5..8d2b974 100644 | |
--- a/lib/dns_uv.js | |
+++ b/lib/dns_uv.js | |
@@ -142,7 +142,23 @@ exports.lookup = function(domain, family, callback) { | |
} | |
} | |
- var wrap = cares.getHostByName(domain, familyToSym(family), onanswer); | |
+ var wrap; | |
+ | |
+ if (family) { | |
+ // resolve names for explicit address family | |
+ var af = familyToSym(family); | |
+ wrap = cares.getHostByName(domain, af, onanswer); | |
+ } else { | |
+ // first resolve names for v4 and if that fails, try v6 | |
+ wrap = cares.getHostByName(domain, cares.AF_INET, function(err, domains4) { | |
+ if (domains4 && domains4.length) { | |
+ callback(null, domains4[0], 4); | |
+ } else { | |
+ cares.getHostByName(domain, cares.AF_INET6, onanswer); | |
+ } | |
+ }); | |
+ } | |
+ | |
if (!wrap) { | |
throw errnoException(errno, 'getHostByName'); | |
} | |
-- | |
1.7.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment