From 070ff1893f56d17ed47e78696c81b74b1e9fa1d2 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 5 Jun 2022 22:04:48 +0200 Subject: [PATCH] fixup! fixup! net: make `server.address()` return a string for `family` --- doc/api/dns.md | 10 +++++----- lib/dns.js | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/doc/api/dns.md b/doc/api/dns.md index f9b2814b06ddda..0d281fdffe051f 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -183,7 +183,7 @@ changes: pr-url: https://github.com/nodejs/node/pull/43054 description: For compatibility with `node:net`, when passing an option object the `family` option can be the string `'IPv4'` or the - string `'IPv6'`, in which case its value will be ignored. + string `'IPv6'`. - version: v18.0.0 pr-url: https://github.com/nodejs/node/pull/41678 description: Passing an invalid callback to the `callback` argument @@ -202,10 +202,10 @@ changes: * `hostname` {string} * `options` {integer | Object} - * `family` {integer} The record family. Must be `4`, `6`, or `0`. For backward - compatibility reasons,`'IPv4'` and `'IPv6'` are interpreted as `0`. The - value `0` indicates that IPv4 and IPv6 addresses are both returned. - **Default:** `0`. + * `family` {integer|string} The record family. Must be `4`, `6`, or `0`. For + backward compatibility reasons,`'IPv4'` and `'IPv6'` are interpreted as `4` + and `6` respectively. The value `0` indicates that IPv4 and IPv6 addresses + are both returned. **Default:** `0`. * `hints` {number} One or more [supported `getaddrinfo` flags][]. Multiple flags may be passed by bitwise `OR`ing their values. * `all` {boolean} When `true`, the callback returns all resolved addresses in diff --git a/lib/dns.js b/lib/dns.js index 818ba43c351402..5bb572e5f29ba9 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -142,8 +142,10 @@ function lookup(hostname, options, callback) { if (options?.family != null) { switch (options.family) { case 'IPv4': + family = 4; + break; case 'IPv6': - family = 0; + family = 6; break; default: validateOneOf(options.family, 'options.family', validFamilies, true);