Skip to content

Commit

Permalink
handle ipv6 addresses suffixed with scope id
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Jul 11, 2019
1 parent cedd3f7 commit a2e5380
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 4 additions & 1 deletion plugins/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,16 @@ module.exports = ({ scope = 'device', host, port, external, allowHalfOpen, pause
// We want to avoid using `host` if the target scope is public and some
// external host (like example.com) is defined.
const externalHost = targetScope === 'public' && external
const resultHost = externalHost || host || scopes.host(targetScope)
let resultHost = externalHost || host || scopes.host(targetScope)

if (resultHost == null) {
// The device has no network interface for a given `targetScope`.
return null
}

// Remove IPv6 scopeid suffix, if any, e.g. `%wlan0`
resultHost = resultHost.replace(/(\%\w+)$/, '')

return toAddress(resultHost, port)
}
}
Expand Down
21 changes: 20 additions & 1 deletion test/plugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ tape('combined, ipv6', function (t) {
})
})

if (has_ipv6)
tape('stringify() does not show scopeid from ipv6', function (t) {
var combined = Compose([
Net({
scope: 'private',
port: 4848,
host: 'fe80::1065:74a4:4016:6266%wlan0'
}),
shs
])
var addr = combined.stringify('private')
t.equal(
addr,
'net:fe80::1065:74a4:4016:6266:4848~shs:' +
keys.publicKey.toString('base64')
)
t.end()
})

tape('net: do not listen on all addresses', function (t) {
var combined = Compose([
Net({
Expand Down Expand Up @@ -361,7 +380,7 @@ function testAbort (name, combined) {
close(function() {t.end()})
}, 500)
})

abort()

})
Expand Down

0 comments on commit a2e5380

Please sign in to comment.