Skip to content

Commit

Permalink
test: fix test-dgram-udp6-link-local-address on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Sep 5, 2021
1 parent c6b0ae8 commit 45526dc
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions test/parallel/test-dgram-udp6-link-local-address.js
Expand Up @@ -8,10 +8,10 @@ const dgram = require('dgram');
const os = require('os');

function linklocal() {
for (const [ifname, entries] of Object.entries(os.networkInterfaces())) {
for (const entries of Object.values(os.networkInterfaces())) {
for (const { address, family, scopeid } of entries) {
if (family === 'IPv6' && address.startsWith('fe80:')) {
return { address, ifname, scopeid };
return { address, scopeid };
}
}
}
Expand All @@ -21,7 +21,6 @@ const iface = linklocal();
if (!iface)
common.skip('cannot find any IPv6 interfaces with a link local address');

const address = `${iface.address}%${iface.ifname}`;
const message = 'Hello, local world!';

// Create a client socket for sending to the link-local address.
Expand All @@ -32,7 +31,7 @@ const server = dgram.createSocket('udp6');

server.on('listening', common.mustCall(() => {
const port = server.address().port;
client.send(message, 0, message.length, port, address);
client.send(message, 0, message.length, port, iface.address);
}));

server.on('message', common.mustCall((buf, info) => {
Expand All @@ -42,10 +41,10 @@ server.on('message', common.mustCall((buf, info) => {
// including the link local scope identifier.
assert.strictEqual(
info.address,
common.isWindows ? `${iface.address}%${iface.scopeid}` : address
common.isWindows ? `${iface.address}%${iface.scopeid}` : iface.address
);
server.close();
client.close();
}, 1));

server.bind({ address });
server.bind({ address: iface.address });

0 comments on commit 45526dc

Please sign in to comment.