|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75721 MCAST_JOIN_GROUP is broken for FreeBSD
Submitted: 2017-12-22 01:17 UTC Modified: -
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: jonathan at tangential dot ca Assigned:
Status: Open Package: Sockets related
PHP Version: 7.0.26 OS: FreeBSD 10.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jonathan at tangential dot ca
New email:
PHP Version: OS:


 [2017-12-22 01:17 UTC] jonathan at tangential dot ca
FreeBSD supports listening on/joining both IPv4 and IPv6 multicast groups. However, it handles full RFC 3678 support (including IPv6) via a different interface (setsourcefilter vs setsockopt).

In order to properly support multicast on FreeBSD (including IPv6 support), one would have to (conditionally) use setsourcefilter instead of setsockopt (throughout much of ext/sockets/multicast.c).

Since I don't have the requirement or will to implement this with FreeBSD's newer protocol agnostic sourcefilter APIs, I've chosen to take the easy way out and just make it work with IPv4 only.

This bug report should likely be split into two bugs as I've only addressed the IPv4 case for now.

I've included versions that correspond to my environment. However, this is far more generally applicable.

This bug is the FreeBSD variant/equivalent of bug #63000 (which was for macOS).

Please see the following FreeBSD documentation references (for details on FreeBSD's multicast support):

Test script:

// This just listens for MDNS traffic. You could optionally dispatch a query if your test network doesn't have a bunch of MDNS traffic

$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (!socket_set_option($socket, IPPROTO_IP, MCAST_JOIN_GROUP, array('group' => '', 'interface' => 0))) {
	echo socket_strerror(socket_last_error());
socket_set_option($socket, SOL_SOCKET, SO_REUSEPORT, 1);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 10, 'usec' => 0]);
socket_bind($socket, '', 5353);

// socket_sendto($socket, $data, strlen($data), 0, '', 5353);

$response = socket_read($socket, 1024, PHP_BINARY_READ);

Expected result:
true (and actually seeing multicast packets destined for the requested group address)

Actual result:
false (with a pass-through error message referencing code [22]/EINVAL)


FreeBSD-use-IP_ADD_MEMBERSHIP.patch (last revision 2017-12-22 01:18 UTC by jonathan at tangential dot ca)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-22 01:47 UTC] jonathan at tangential dot ca
It looks like FreeBSD does actually support RFC 3678 via setsockopt (See `sys/netinet/in_mcast.c`). However, it did not work for me until I rebuilt the sockets module so that it uses the `IP_ADD_MEMBERSHIP`/IP_DROP_MEMBERSHIP` flags instead. I may have to see whether I can reproduce the issue in another jail.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 29 02:03:37 2021 UTC