On Tuesday 06 January 2009 17:49:49 Peter Steele wrote:
> Our efforts so far indicate the answer is no, which baffles us. We want
> to send a limited broadcast to but the message never
> arrives. The same code works fine under Linux. Is there a trick for
> doing this kind of thing under FreeBSD?

Did you enable SO_BROADCAST and IP_ONESBCAST on the socket? I remember needing 
this on FreeBSD but not on Linux. I know UDP broadcasting works fine, but is 
somewhat more involved:

addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("");
addr.sin_port = htons(UDP_PORT_ET);

optval = 1;
if(setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof optval) == -1)
        err(1, "setsockopt");

optval = 1;
if(setsockopt(sock, IPPROTO_IP, IP_ONESBCAST, &optval, sizeof optval) == -1)
        err(1, "setsockopt");

const char data[] = "report";

if(sendto(sock, data, sizeof data, 0, (struct sockaddr*)&addr, addrlen) == -1)

This code will send a packet with destination address, on the 
interface with broadcast address netintro(4) talks about how 
to discover these addresses. SO_ONESBCAST is documented in ip(4), SO_BROADCAST 
in getsockopt(4).

Pieter de Goeje

freebsd-questions@freebsd.org mailing list
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to