Help Broadcasting a UDP packet on the LAN:URGENT

Bruce M Simpson bms at spc.org
Mon Oct 20 12:00:34 PDT 2003


On Mon, Oct 20, 2003 at 10:47:51AM -0700, sarat chandra Annadata wrote:
> I am need of some urgent techinical help to pull me out of a little problem. I have been 
> trying to broadcast a UDP packet(actually it is a DHCP offer packet) but 
> havent' successfully done it sofar. The following is the descripttion 
> about how I have been trying to do it.
>  1) I am creating a socket with sock_dgram option.
>  2)Next I am filling up the sockaddr_in structure, with IP address 
> 255.255.255.255 and port number as DHCP client port number.
[snip]

Undirected broadcasts will only work if you do the following:-

 1) Use a version of FreeBSD which supports the IP_ONESBCAST socket
    option. I committed this to HEAD and RELENG_4 branches somewhat over
    a month ago. Backporting the patch shouldn't be too difficult.

 2) Enable the IP_ONESBCAST and SO_BROADCAST ip/socket level options.

 3) Discover the IP broadcast address corresponding to the interface upin
    which you wish to send the datagram.

 4) Use the sendto() or send() socket calls to send the datagram, *with
    the interface's IP broadcast address set as the destination*.

The directed broadcast address is substituted with 255.255.255.255 at
send time, after routing takes place, and before the datagram is handed off
to the lower-layer network card drivers.

BMS


More information about the freebsd-net mailing list