Subject: Broadcasting to 255.255.255.255
To: None <netbsd-users@netbsd.org>
From: Ian McIntosh <ianm@cat.co.za>
List: netbsd-users
Date: 07/13/2007 17:25:38
Hi all

I am trying to create a small app to broadcast to 255.255.255.255 and have come across a problem.
A search of the user archives showed me that someone else had the same problem a few years back 
(10/11/2001 20:48:19) - however I could not find a response to the query.

The query is quoted below:

"
How do I send UDP datagrams to 255.255.255.255 on NetBSD?

I'm trying to port a Linux app that broadcasts on that address in order to
discover an unconfigured network appliance. It does so by:

  setsockopt(lsendsock, SOL_SOCKET, SO_BROADCAST, &dummy, sizeof(dummy))

and then

  dst.sin_addr.s_addr = 0xffffffff;
  dst.sin_port = htons(EUCP_SERVERPORT);
  dst.sin_family = AF_INET;

  sendto(lsendsock, packet, len, 0, (struct sockaddr *)&dst, sizeof(dst)))

But tcpdump tells me that NetBSD makes the broadcast network specific:

  20:20:28.196043 kvik.lan.dinsen.net.62476 > 192.168.1.255.30292:  udp 16

But the box is unconfigured, so it doesn't know that it's part of this
network, and doesn't answer.

Stevens Network Programming vol 1 says in section 18.2 Broadcast Addresses
(p. 471):

"Most hosts allow [sending a UDP datagram to 255.255.255.255] [...] and
convert the address to the subnet-directed broadcast address of the
outgoing interface. BSD/OS has [...] IP_ONESBCAST, and when set, the
destination IP address for broadcasts is 255.255.255.255 [...]"

NetBSD doesn't have this option, so how do we do it?
"
Is it possible to do something like this in netBSD? 
I am using netBSD 3.0_STABLE and 1.62_STABLE

Thanks
Ian