You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dns docs are missing that family = 0 for dns.lookup is allowed #28159
Quick question: is dns.lookup(url, 0, callback) supported as part of Node's API? The documentation says Must be 4 or 6, and any positive integer other than 4 or 6 will return a TypeError [ERR_INVALID_OPT_VALUE]: The value "2" is invalid for option "family". But passing in 0 does not error. Is this expected? If so, is this something stable that developers can rely on?
// The following are all expected to workdns.lookup('www.google.com',4,err=>{console.log(err);// null});dns.lookup('www.google.com',6,err=>{console.log(err);// null});dns.lookup('www.google.com',err=>{console.log(err);// null});// The following should errortry{dns.lookup('www.google.com',1,()=>{});}catch(e){console.log(e);// TypeError [ERR_INVALID_OPT_VALUE]: The value "1" is invalid for option "family"}try{dns.lookup('www.google.com',2,()=>{});}catch(e){console.log(e);// TypeError [ERR_INVALID_OPT_VALUE]: The value "2" is invalid for option "family"}try{dns.lookup('www.google.com',3,()=>{});}catch(e){console.log(e);// TypeError [ERR_INVALID_OPT_VALUE]: The value "3" is invalid for option "family"}try{dns.lookup('www.google.com',5,()=>{});}catch(e){console.log(e);// TypeError [ERR_INVALID_OPT_VALUE]: The value "5" is invalid for option "family"}// Asking about this one:dns.lookup('www.google.com',0,err=>{console.log(err);// null <-- is this correct?});
0 stands for AF_UNSPEC, which, quoting the man page, means:
The value AF_UNSPEC indicates that getaddrinfo() should return socket addresses for any address family (either IPv4 or IPv6, for example) that can be used with node and service.
So, the Node.js documentation is clearly wrong, and omitting an important feature here (although it’s the default behaviour). I’m moving this over to the main repo as it’s a documentation bug.
Activity
addaleax commentedon Jun 10, 2019
0stands forAF_UNSPEC, which, quoting the man page, means:So, the Node.js documentation is clearly wrong, and omitting an important feature here (although it’s the default behaviour). I’m moving this over to the main repo as it’s a documentation bug.
[-]is family = 0 for dns.lookup allowed?[/-][+]dns docs are missing that family = 0 for dns.lookup is allowed[/+]doc: document behavior of family:0 in dns.lookup()
ZYSzys commentedon Jun 14, 2019
Fixed via #28163.
doc: document behavior of family:0 in dns.lookup()
doc: document behavior of family:0 in dns.lookup()