-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Describe the bug
The sockets on MacOS binded to ::0 and 0.0.0.0 are not able to receive incoming multicast packets despite having addMembership called. Despite this, these sockets are still able to receive the multicast packets sent on the same interface with IP_MULTICAST_LOOP enabled.
This behavior is not exhibited with Linux hosts.
The MacOS system dns-sd command is able to find registered services from other devices made by our MDNS stack. This means that the only explanation our MDNS stack on a MacOS host not finding the registered service is that the the socket.addMembership is silently failing, or we are passing it incorrect parameters on MacOS specifically.
If this is not fixed, js-mdns on MacOS would only be able to facilitate discovery on the same device
To Reproduce
import type { Hostname, Port } from '@/types';
import * as events from '@/events';
import MDNS from '@/MDNS';
describe(MDNS.name, () => {
let mdns1: MDNS;
let mdns2: MDNS;
beforeEach(async () => {
mdns1 = new MDNS();
mdns2 = new MDNS();
});
afterEach(async () => {
await mdns1.stop();
await mdns2.stop();
});
test('register', async () => {
const mdnsPort = 5353 as Port;
const mdns2Hostname = 'polykey2' as Hostname;
await mdns2.start({ hostname: mdns2Hostname, port: mdnsPort, groups: ['224.0.0.251'] });
const service = {
name: 'test2',
port: mdnsPort,
protocol: 'udp',
type: 'polykey',
} as Parameters<typeof MDNS.prototype.registerService>[0];
mdns2.registerService(service);
await new Promise(() => {})
});
test('query', async () => {
const mdnsPort = 5353 as Port;
const mdns1Hostname = 'polykey2' as Hostname;
await mdns1.start({
hostname: mdns1Hostname,
port: mdnsPort,
advertise: false,
});
mdns1.startQuery({
protocol: 'udp',
type: 'polykey',
});
await new Promise((resolve) => {
mdns1.addEventListener(
events.EventMDNSService.name,
(e: events.EventMDNSService) => {
console.log(e);
resolve(null);
},
);
});
});
});Run npm run test -- -t 'register' on a non-MacOS system.
Run npm run test -- -t 'query' on a MacOS system.
The expectation is that an event will be logged on the MacOS system for the service being discovered. A console.log can also be put after handleSocketMessage under if (packet.id === this._id) return; to show that no incoming multicast packets have been received. (must be placed after this statement, so that packets sent by the MacOS host itself are filtered out)
Expected behavior
Incoming multicast packets should be correctly received by the the multicast sockets bound by MDNS.
Screenshots
Platform (please complete the following information)
- Device: Macmini9,1
- OS: MacOS 13.1 (Build 22C65)
- Version: v20.5.1
Additional context
- https://nodejs.org/api/dgram.html#socketaddmembershipmulticastaddress-multicastinterface
- https://stackoverflow.com/questions/65534342/receiving-udp-multicast-on-macos-big-sur