Here's some working code on my main machine.
#!/usr/bin/perl
use strict; # https://perlmonks.org/?node_id=11161465
use warnings;
use IO::Socket::Multicast;
my $s = IO::Socket::Multicast->new or die $@;
$s->mcast_if( 'tybalt' );
$s->mcast_dest(scalar sockaddr_in(9999, inet_aton('239.1.1.1')));
my $me = qx(hostname) =~ tr/\n//dr;
open my $la, '<', '/proc/loadavg' or die "$! opening loadavg";
while(1)
{
seek $la, 0, 0;
my $data = "$me " . localtime . ' ' . <$la>;
print "data: $data";
$s->mcast_send($data) or die "$! on send";
sleep 1;
}
#!/usr/bin/perl
use strict; # https://perlmonks.org/?node_id=11161465
use warnings;
use IO::Socket::Multicast;
my $s = IO::Socket::Multicast->new(LocalPort => 9999) or die $@;
$s->mcast_add('239.1.1.1', 'tybalt') or die "group $!";
while(1)
{
$s->recv(my $data, 1024);
print $data;
}
This machine has TWO interfaces, one of which is named 'tybalt' (sort of like 'eth0' but different :).
This code would not work until I added the interface name in the appropriate places.
On another similar machine that has only one interface, the interface name was not required. Neither was the interface name required on
a raspberry pi running Manjaro.
So my working theory is that if you have more than one interface, interface names are required.
Interestingly, omitting the interface name from the mcast_add method for the two interface machine does not cause an error, it just doesn't get the multicast messages.
Two machines are running ArchLinux and one is running Manjaro. All three can multicast to each other, and all three are receiving all multicasts.
Note also that none of my machines would take a string in mcast_dest, nor would they take a string as the second argument of mcast_send.