Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Jan 2009 10:10:44 +0100
From:      Pieter de Goeje <>
Cc:        Peter Steele <>
Subject:   Re: Do UDP broadcasts work in FreeBSD?
Message-ID:  <>
In-Reply-To: <>
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
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

Want to link to this message? Use this URL: <>