Skip to content

Commit

Permalink
fix dgram breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed May 16, 2022
1 parent d78b8c4 commit 9d5bcc7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function defaultInterface () {
var net = networks[names[i]]
for (var j = 0; j < net.length; j++) {
var iface = net[j]
if (iface.family === 'IPv4' && !iface.internal) {
if (isIPv4(iface.family) && !iface.internal) {
if (os.platform() === 'darwin' && names[i] === 'en0') return iface.address
return '0.0.0.0'
}
Expand All @@ -189,7 +189,7 @@ function allInterfaces () {
var net = networks[names[i]]
for (var j = 0; j < net.length; j++) {
var iface = net[j]
if (iface.family === 'IPv4') {
if (isIPv4(iface.family)) {
res.push(iface.address)
// could only addMembership once per interface (https://nodejs.org/api/dgram.html#dgram_socket_addmembership_multicastaddress_multicastinterface)
break
Expand All @@ -199,3 +199,7 @@ function allInterfaces () {

return res
}

function isIPv4 (family) { // for backwards compat
return family === 4 || family === 'IPv4'
}

0 comments on commit 9d5bcc7

Please sign in to comment.