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("172.30.255.255");
>
> 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: $!";
>
> For some reason I'm getting "send: Can't assign requested address"
> for INADDR_BROADCAST. How can it *not* assign that? Flipping the
> comments over works fine (for that subnet) -- in other words, in my
> C code, I have to spelunk the interface list with ioctl()s and then
> get the sodding broadcast address. Which is a lot of work :-(
>
> FWIW (this is on the failing machine, yes different subnet),
>
> en0: flags=8963<UP,BROADCAST,b6,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
> inet 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255
> ether 00:30:65:7e:d1:96
> media: autoselect (none) status: inactive
> supported media: none autoselect 10baseT/UTP <half-duplex> 10baseT/UTP
><full-duplex> 100baseTX <half-duplex> 100baseTX <full-duplex>
If you have a complete /usr/src installed, look in there for examples
of how it's done in C (it looks like you have a BSD machine - so it's
quite likely /usr/src is populated).
Darn, your example works on both the Linux and FreeBSD machines I just
tried it on. What machine are you using? On both machines, EADDRNOTAVAIL
(what you're seeing) isn't even listed as an error in the man page.
Try running perl under strace or truss or ktrace, whatever your native
tracing tool is.
-Dom