On Wed, Apr 18, 2001 at 03:25:09AM -0700, Paul Makepeace wrote:
> Anyone hackers here sent broadcast packets? I think this is how you
> do it:
> #!/usr/bin/perl -w
> use strict;
> use Socket;
> my $dst = inet_aton("");
> socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname("udp"))
>         or die "socket: $!";
> setsockopt(SOCKET, SOL_SOCKET, SO_BROADCAST, pack("l", 1))
>         or die "setsockopt: $!";
> send(SOCKET, "hello", 0, sockaddr_in(6868, INADDR_BROADCAST))  
> #send(SOCKET, "hello", 0, sockaddr_in(6868, $dst))
>         or die "send: $!";

I'd agree, tho' I don't think you need to pack() the last arg to
> For some reason I'm getting "send: Can't assign requested address"
> for INADDR_BROADCAST. How can it *not* assign that? Flipping the

I had a lot of fun&games with this (before LDS's book came out!):
Trying both IO::Socket and Socket.pm, I could do either read or
write but not both ... and had that msg.
My definitely working version is:

        socket(SOCK, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
                || die "$prog: socket: $!\n";
        my $rip = INADDR_BROADCAST;
        $rip = inet_aton($opt{d})       if defined $opt{d};
        my $raddr = sockaddr_in($opt{p}, $rip);
        setsockopt(SOCK, SOL_SOCKET, SO_BROADCAST, 1)   
                || die "$prog: setsockopt: $!\n";
        send(SOCK, $msg . "\015\012", 0, $raddr) 
                || die "$prog: send: $!\n";

Which looks the same but for the pack().

Chris Benson

Reply via email to