From owner-freebsd-net@FreeBSD.ORG Wed Apr 8 22:33:09 2015 Return-Path: Delivered-To: net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8BAB35AF for ; Wed, 8 Apr 2015 22:33:09 +0000 (UTC) Received: from remote.thehowies.com (50-197-91-217-static.hfc.comcastbusiness.net [50.197.91.217]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client CN "remote.thehowies.com", Issuer "RapidSSL CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5A57D368 for ; Wed, 8 Apr 2015 22:33:08 +0000 (UTC) Received: from PRIMARY.thehowies.local ([fe80::497b:de8e:1045:4c2a]) by PRIMARY.thehowies.local ([fe80::497b:de8e:1045:4c2a%24]) with mapi id 14.03.0224.002; Wed, 8 Apr 2015 15:31:54 -0700 From: John Howie To: Yuri , "net@freebsd.org" Subject: Re: Socket bound to 0.0.0.0 never receives broadcasts with non-zero IP source address Thread-Topic: Socket bound to 0.0.0.0 never receives broadcasts with non-zero IP source address Thread-Index: AQHQcZ5h2I9CcpL4u0iz7C/8UqpBP51DEDWjgAEFxYD//9CxgA== Date: Wed, 8 Apr 2015 22:31:53 +0000 Message-ID: References: <55248957.60109@rawbw.com> <878ue2n6lu.fsf@corbe.net> <55259BC7.6040502@rawbw.com> In-Reply-To: <55259BC7.6040502@rawbw.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/14.4.7.141117 x-originating-ip: [12.130.116.80] Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: Daniel Corbe X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Apr 2015 22:33:09 -0000 Hi Yuri, Is your machine a router or gateway, or have a firewall? Are you trying to capture all broadcast packets, or just UDP targeted and broadcast packets to a particular port? Regards, John On 4/8/15, 5:21 PM, "Yuri" wrote: >On 04/08/2015 05:32, Daniel Corbe wrote: >> If nobody answers this question by the time I get home I'll try and >> help; however, in the mean time I do have a couple of suggestions. >> >> Have you tried writing the equivalent program in C using the sockets >> API? IE is this a python specific problem or a sockets problem in >> general? >> >> The second thing is you may just want to try using raw sockets instead. > >I verified before with ktrace, and now, following your suggestion, >rewrote it in C, and result is the same. >When I change SOCK_DGRAM->SOCK_RAW it keeps getting some other packets, >sin_port doesn't seem to matter. Also, UDP is the practically important >case. > >Unless there is some reasonable explanation why ip source address can >influence reception, I believe this is a bug in kernel. And pretty >important one, because it can hurt DHCP servers. > >Yuri > > >--- C program exhibiting the problem --- > >#include >#include >#include >#include >#include > >#define CK(func, call...) if ((call) < 0) {perror(#func); exit(1);} > >int main() { > int sock, one =3D 1; > ssize_t count; > struct sockaddr_in sa; > char buffer[4096]; > struct sockaddr_storage src_addr; > > struct iovec iov[1]; > iov[0].iov_base=3Dbuffer; > iov[0].iov_len=3Dsizeof(buffer); > > struct msghdr msg; > msg.msg_name=3D&src_addr; > msg.msg_namelen=3Dsizeof(src_addr); > msg.msg_iov=3Diov; > msg.msg_iovlen=3D1; > msg.msg_control=3D0; > msg.msg_controllen=3D0; > > CK(socket, sock =3D socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) > CK(setsockopt, setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, >sizeof(one))) > CK(setsockopt, setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &one, >sizeof(one))) > sa.sin_family =3D AF_INET; > sa.sin_addr.s_addr =3D htonl(INADDR_ANY); > //sa.sin_port =3D htons(67); > sa.sin_port =3D htons(1767); > CK(bind, bind(sock, (const struct sockaddr*)&sa, sizeof(sa))) > > printf("Waiting for broadcast\n"); > CK(recvmsg, count =3D recvmsg(sock, &msg, 0)) > printf("Received broadcast packet: %zd bytes\n", count); > > return 0; >} > >_______________________________________________ >freebsd-net@freebsd.org mailing list >http://lists.freebsd.org/mailman/listinfo/freebsd-net >To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"