@ -100,46 +100,93 @@ exports.getHostByName = function (domain, callback) {
var net ;
// Easy DNS A/AAAA look up
exports . lookup = function ( domain , callback ) {
var addressType = dns . isIP ( domain ) ;
if ( addressType ) {
process . nextTick ( function ( ) {
callback ( null , domain , addressType ) ;
} ) ;
// lookup(domain, [family,] callback)
exports . lookup = function ( domain , family , callback ) {
if ( arguments . length === 2 ) {
callback = family ;
family = undefined ;
} else if ( family && family !== 4 && family !== 6 ) {
family = parseInt ( family ) ;
if ( family === dns . AF_INET ) {
family = 4 ;
} else if ( family === dns . AF_INET6 ) {
family = 6 ;
} else if ( family !== 4 && family !== 6 ) {
throw new Error ( 'invalid argument: "family" must be 4 or 6' ) ;
}
}
if ( ! domain ) {
callback ( null , null , family === 6 ? 6 : 4 ) ;
return ;
}
var matchedFamily = dns . isIP ( domain ) ;
if ( matchedFamily ) {
callback ( null , domain , matchedFamily ) ;
} else {
if ( /\w\.local\.?$/ . test ( domain ) ) {
if ( /\w\.local\.?$/ . test ( domain ) ) {
// ANNOYING: In the case of mDNS domains use NSS in the thread pool.
// I wish c-ares had better support.
process . binding ( 'net' ) . getaddrinfo ( domain , 4 , function ( err , domains4 ) {
callback ( err , domains4 [ 0 ] , 4 ) ;
} ) ;
} else {
channel . getHostByName ( domain , dns . AF_INET , function ( err , domains4 ) {
if ( domains4 && domains4 . length ) {
callback ( null , domains4 [ 0 ] , 4 ) ;
} else {
channel . getHostByName ( domain , dns . AF_INET6 , function ( err , domains6 ) {
if ( domains6 && domains6 . length ) {
callback ( null , domains6 [ 0 ] , 6 ) ;
if ( family ) {
// resolve names for explicit address family
var af = ( family === 4 ) ? dns . AF_INET : dns . AF_INET6 ;
channel . getHostByName ( domain , af , function ( err , domains ) {
if ( ! err && domains && domains . length ) {
if ( family !== dns . isIP ( domains [ 0 ] ) ) {
callback ( new Error ( 'not found' ) , [ ] ) ;
} else {
callback ( err , [ ] ) ;
callback ( null , domains [ 0 ] , family ) ;
}
} ) ;
}
} ) ;
} else {
callback ( err , [ ] ) ;
}
} ) ;
} else {
// first resolve names for v4 and if that fails, try v6
channel . getHostByName ( domain , dns . AF_INET , function ( err , domains4 ) {
if ( domains4 && domains4 . length ) {
callback ( null , domains4 [ 0 ] , 4 ) ;
} else {
channel . getHostByName ( domain , dns . AF_INET6 ,
function ( err , domains6 ) {
if ( domains6 && domains6 . length ) {
callback ( null , domains6 [ 0 ] , 6 ) ;
} else {
callback ( err , [ ] ) ;
}
} ) ;
}
} ) ;
}
}
}
} ;
exports . resolve4 = function ( domain , callback ) { channel . query ( domain , dns . A , callback ) } ;
exports . resolve6 = function ( domain , callback ) { channel . query ( domain , dns . AAAA , callback ) } ;
exports . resolveMx = function ( domain , callback ) { channel . query ( domain , dns . MX , callback ) } ;
exports . resolveTxt = function ( domain , callback ) { channel . query ( domain , dns . TXT , callback ) } ;
exports . resolveSrv = function ( domain , callback ) { channel . query ( domain , dns . SRV , callback ) } ;
exports . reverse = function ( domain , callback ) { channel . query ( domain , dns . PTR , callback ) } ;
exports . resolveNs = function ( domain , callback ) { channel . query ( domain , dns . NS , callback ) } ;
exports . resolve4 = function ( domain , callback ) {
channel . query ( domain , dns . A , callback ) ;
} ;
exports . resolve6 = function ( domain , callback ) {
channel . query ( domain , dns . AAAA , callback ) ;
} ;
exports . resolveMx = function ( domain , callback ) {
channel . query ( domain , dns . MX , callback ) ;
} ;
exports . resolveTxt = function ( domain , callback ) {
channel . query ( domain , dns . TXT , callback ) ;
} ;
exports . resolveSrv = function ( domain , callback ) {
channel . query ( domain , dns . SRV , callback ) ;
} ;
exports . reverse = function ( domain , callback ) {
channel . query ( domain , dns . PTR , callback ) ;
} ;
exports . resolveNs = function ( domain , callback ) {
channel . query ( domain , dns . NS , callback ) ;
} ;
var resolveMap = {
'A' : exports . resolve4 ,