Skip to content

Commit 52e600a

Browse files
committed
test: don't assume broadcast traffic is unfiltered
parallel/test-dgram-broadcast-multi-process assumes non-local broadcast traffic is unfiltered, an assumption that fails with, for example, the default Fedora firewall rules. Use a loopback interface instead. Fixes: nodejs#219 PR-URL: nodejs#220 Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent eaed2a1 commit 52e600a

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

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

+2-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var common = require('../common'),
2323
assert = require('assert'),
2424
dgram = require('dgram'),
2525
util = require('util'),
26-
networkInterfaces = require('os').networkInterfaces(),
2726
Buffer = require('buffer').Buffer,
2827
fork = require('child_process').fork,
2928
LOCAL_BROADCAST_HOST = '255.255.255.255',
@@ -35,19 +34,6 @@ var common = require('../common'),
3534
new Buffer('Fourth message to send')
3635
];
3736

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-
5137
if (process.argv[2] !== 'child') {
5238
var workers = {},
5339
listeners = 3,
@@ -164,7 +150,7 @@ if (process.argv[2] !== 'child') {
164150

165151
// bind the address explicitly for sending
166152
// INADDR_BROADCAST to only one interface
167-
sendSocket.bind(common.PORT, bindAddress);
153+
sendSocket.bind(common.PORT, '127.0.0.1');
168154
sendSocket.on('listening', function () {
169155
sendSocket.setBroadcast(true);
170156
});
@@ -211,7 +197,7 @@ if (process.argv[2] === 'child') {
211197

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

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

0 commit comments

Comments
 (0)