Reinhard
Reinhard

Reputation: 110

How to send an IP broadcast message using Perl

I've tried both Net::RawIP and Net::Write::Layer3. It works fine if i supply a specific ip address in the network. while i'm getting either

sendto() at /usr/lib/perl5/Net/RawIP.pm line 630. shell returned 13

or

Net::Write::Layer::send: Permission denied

if i change the destination address to 66.66.66.255

any ideas?

the code i'm using is here

use Net::Write::Layer qw(:constants);
use Net::Write::Layer3;
use NetAddr::IP;
use Net::RawIP;

$message = "Foo";

# using Net::RawIP
$n = Net::RawIP->new({
                        ip  => {
                            tos => 0xC0,
                            daddr => '66.66.66.2',
                            protocol => 2,
                        },
                        generic => {
                            data => $message
                        }
                    });
$n->send;

# using Net::Write::Layer3
my $desc = Net::Write::Layer3->new(
                dst      => '66.66.66.2',
                protocol => '2',
                family   => NW_AF_INET,
);    
$desc->open;
$desc->send($message);
$desc->close;

Upvotes: 1

Views: 700

Answers (1)

Alnitak
Alnitak

Reputation: 339816

Error 13 is usually EACCES - i.e. you do not have sufficient permission to send to a broadcast socket.

Upvotes: 1

Related Questions