short code snippit showing howto use UDP for broadcasting to a whole subnet of addresses
couldn't find this in any of the books...
simple but you have to figure it out...
#!/usr/bin/perl
#
use strict;
use IO::Socket;
# defaults
my $bcaddr = '192.168.254.255';
my $port = 9870;
socket(sock, PF_INET, SOCK_DGRAM, getprotobyname("udp"))
or die "socket:$@";
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, 1)
or die "setsockopt:$@";
my $dest = sockaddr_in($port,inet_aton($bcaddr));
# 10 udp's on the wire
for (my $i=0;$i < 10;$i++) {
my $data = 'UDP packet ' . $i;
# send udp packet
send(sock,$data,0,$dest) || die "send(): $!";
}