in reply to Re: udp broadcast: doesn't work in Linux
in thread udp broadcast: doesn't work in Linux

thanks cjensen!
I added the following just below the socket creation and above the send method:
print "\ngetpeername: " . getpeername($sock) . "\n";
output is:
getpeername: send: Cannot determine peer address at udp.pl line 26
so, no error when calling getpeername...
checking the linux kernel road.. woulb be very strange if you cannot send something to a LAN broadcast address
tried other port values... nothing (port is random)
F.

Replies are listed 'Best First'.
Re: Re: Re: udp broadcast: doesn't work in Linux
by cjensen (Sexton) on Oct 12, 2001 at 00:39 UTC
    I should have been more clear... The error is occurring when the peer name is undefined in IO::Socket. It won't give you an error when it can't determine the peer address, it just returns undef. Then the call to send in IO::Socket croaks when peer name is undefined:

        croak 'send: Cannot determine peer address'
             unless($peer);
    
    So getpeername($sock) returning undef is what I expected would happen, I just didn't explain that well enough. It should return the address of the peer at the remote end of the socket.

    Try this and vary the $bcaddr in your script:

    my ($port, $addr) = unpack_sockaddr_in(getpeername($sock));
    my $host = gethostbyaddr($addr, AF_INET);
    print "Host:\t$host\n";
    print "Port:\t$port\n";