Skip to content

Commit df3c4ca

Browse files
committed
Revert "test: don't assume broadcast traffic is unfiltered"
This reverts commit 52e600a. Reverted for: * making the test fail with ENETUNREACH on OS X 10.8, and * making the test fail with EHOSTDOWN on OS X 10.9 and 10.10 when there is no network connectivity, and * leaving behind orphan processes that make subsequent tests fail with EADDRINUSE errors PR-URL: #259 Reviewed-By: Rod Vagg <[email protected]>
1 parent 4519db0 commit df3c4ca

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/parallel/test-dgram-broadcast-multi-process.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var common = require('../common'),
2323
assert = require('assert'),
2424
dgram = require('dgram'),
2525
util = require('util'),
26+
networkInterfaces = require('os').networkInterfaces(),
2627
Buffer = require('buffer').Buffer,
2728
fork = require('child_process').fork,
2829
LOCAL_BROADCAST_HOST = '255.255.255.255',
@@ -34,6 +35,19 @@ var common = require('../common'),
3435
new Buffer('Fourth message to send')
3536
];
3637

38+
// take the first non-internal interface as the address for binding
39+
get_bindAddress: for (var name in networkInterfaces) {
40+
var interfaces = networkInterfaces[name];
41+
for(var i = 0; i < interfaces.length; i++) {
42+
var localInterface = interfaces[i];
43+
if (!localInterface.internal && localInterface.family === 'IPv4') {
44+
var bindAddress = localInterface.address;
45+
break get_bindAddress;
46+
}
47+
}
48+
}
49+
assert.ok(bindAddress);
50+
3751
if (process.argv[2] !== 'child') {
3852
var workers = {},
3953
listeners = 3,
@@ -150,7 +164,7 @@ if (process.argv[2] !== 'child') {
150164

151165
// bind the address explicitly for sending
152166
// INADDR_BROADCAST to only one interface
153-
sendSocket.bind(common.PORT, '127.0.0.1');
167+
sendSocket.bind(common.PORT, bindAddress);
154168
sendSocket.on('listening', function () {
155169
sendSocket.setBroadcast(true);
156170
});
@@ -197,7 +211,7 @@ if (process.argv[2] === 'child') {
197211

198212
listenSocket.on('message', function(buf, rinfo) {
199213
// receive udp messages only sent from parent
200-
if (rinfo.address !== '127.0.0.1') return;
214+
if (rinfo.address !== bindAddress) return;
201215

202216
console.error('[CHILD] %s received %s from %j',
203217
process.pid,

0 commit comments

Comments
 (0)