From owner-freebsd-questions@FreeBSD.ORG Thu Jan 8 09:22:51 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9AA3C1065676 for ; Thu, 8 Jan 2009 09:22:51 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from s2m-is-001.service2media.com (rev-130-102.virtu.nl [217.114.102.130]) by mx1.freebsd.org (Postfix) with ESMTP id 345758FC21 for ; Thu, 8 Jan 2009 09:22:50 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from nox-laptop.localnet ([10.0.1.45] RDNS failed) by s2m-is-001.service2media.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 8 Jan 2009 10:10:45 +0100 From: Pieter de Goeje To: freebsd-questions@freebsd.org Date: Thu, 8 Jan 2009 10:10:44 +0100 User-Agent: KMail/1.10.3 (Linux/2.6.27-11-generic; KDE/4.1.3; x86_64; ; ) References: <2ACA3DE8F9758A48B8BE2C7A847F91F2479DF3@polaris.maxiscale.com> In-Reply-To: <2ACA3DE8F9758A48B8BE2C7A847F91F2479DF3@polaris.maxiscale.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200901081010.45049.pieter@degoeje.nl> X-OriginalArrivalTime: 08 Jan 2009 09:10:45.0539 (UTC) FILETIME=[FD389730:01C97170] Cc: Peter Steele Subject: Re: Do UDP broadcasts work in FreeBSD? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Jan 2009 09:22:53 -0000 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 255.255.255.255 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("130.89.191.255"); 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) warn("sendto"); This code will send a packet with destination address 255.255.255.255, on the interface with broadcast address 130.89.191.255. netintro(4) talks about how to discover these addresses. SO_ONESBCAST is documented in ip(4), SO_BROADCAST in getsockopt(4). -- Pieter de Goeje