From owner-freebsd-net@FreeBSD.ORG Mon Jul 18 14:41:13 2011 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 226E9106566B; Mon, 18 Jul 2011 14:41:13 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) Received: from kabab.cs.huji.ac.il (kabab.cs.huji.ac.il [132.65.16.84]) by mx1.freebsd.org (Postfix) with ESMTP id D441E8FC16; Mon, 18 Jul 2011 14:41:12 +0000 (UTC) Received: from pampa.cs.huji.ac.il ([132.65.80.32]) by kabab.cs.huji.ac.il with esmtp id 1QioQt-000MJQ-T9; Mon, 18 Jul 2011 17:04:28 +0300 X-Mailer: exmh version 2.7.2 01/07/2005 with nmh-1.2 To: freebsd-net@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 18 Jul 2011 17:04:27 +0300 From: Daniel Braniss Message-ID: Cc: freebsd-hackers@freebsd.org Subject: broadcast oddity X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2011 14:41:13 -0000 this code behaves correctly when run from a diskless host which booted via PXE, but fails on a host that was booted from disk. hint: the non working sends a packet with a non ethernet broadcast address and an ip address of 255.255.255.255, the working version sets the ethernet address to 0xffffffff and the ip to the network broadcast address. what am I doing wrong? danny PS: what is the correct way to obtain the network broadcast address? #include #include #include #include #include #include void bcast() { int so, on; char msg[BUFSIZ]; struct timespec t2; struct sockaddr_in soin; if((so = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { perror("socket"); exit(-1); } on = 1; if(setsockopt(so, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on))) { perror("setsockopt"); exit(-1); } bzero(&soin, sizeof(struct sockaddr_in)); soin.sin_len = sizeof(struct sockaddr_in); soin.sin_family = AF_INET; soin.sin_addr.s_addr = INADDR_BROADCAST; soin.sin_port = htons(12345); while(1) { clock_gettime(CLOCK_REALTIME, &t2); sprintf(msg, "0x%016x", t2.tv_sec); if(sendto(so, msg, strlen(msg)+1, 0, (struct sockaddr *)&soin, sizeof(struct sockaddr)) < 0) { perror("sendto"); break; } sleep(10); } } main(int cc, char **vv) { bcast(); }