From owner-freebsd-net@FreeBSD.ORG Tue Feb 3 12:27:40 2009 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 CC2F91065670; Tue, 3 Feb 2009 12:27:40 +0000 (UTC) (envelope-from dlt@mebtel.net) Received: from mail961c35.nsolutionszone.com (mail961c35.nsolutionszone.com [209.235.152.151]) by mx1.freebsd.org (Postfix) with ESMTP id 949B58FC1C; Tue, 3 Feb 2009 12:27:40 +0000 (UTC) (envelope-from dlt@mebtel.net) X-POP-User: dlt.mebtel.net Received: from localhost (66-79-79-183.dsl.mebtel.net [66.79.79.183]) by mail961c35.nsolutionszone.com (8.13.6.20060614/8.13.1) with ESMTP id n13CRcAe024813; Tue, 3 Feb 2009 12:27:39 GMT Date: Tue, 3 Feb 2009 07:27:37 -0500 From: Derek Tattersall To: Robert Watson Message-ID: <20090203122737.GA62874@oriental.arm.org> References: <20090201183057.GA47405@oriental.arm.org> <20090202222414.GA59860@oriental.arm.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Cc: freebsd-net@FreeBSD.org Subject: Re: Multicast source address in recvfrom() X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: dlt@mebtel.net List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Feb 2009 12:27:41 -0000 * Robert Watson [090203 06:17]: > > >* Robert Watson [090202 17:06]: > >>On Sun, 1 Feb 2009, Derek Tattersall wrote: > >> > >>>In order to become familiar with multicast implementation using FreeBSD, > >>>I found via Google a pair of test programs which multicast sent a simple > >>>text message and received the text message. I added some code to report > >>>the source address, because none of the references that I looked at > >>>specified the source IP address in the frame. > >>> > >>>I ran the sender on A -current system, AMD64 vintage last week. The > >>>receiver was on a -current system I386 vintage last week. TCPDUMP shows > >>>the source IP address in the frame as (correctly) 192.168.0.15. The > >>>receiver reports the source IP address as 200.231.191.191. I have also > >>>run the same test with an OpenBSD 4.4 Release I386 system as the > >>>receiver. The openBSD system reports the sender as 192.168.0.15. A > >>>Fedora 10 system reported the source IP address as 0.0.0.0. > >>> > >>>Googling the RFCs and other information and referring to Comer's and > >>>Stevens' books on TCPIP I can't determine what should be reported. Does > >>>anybody have clue for me? > >> > >>It might depend on how you're querying the source address. Could you > >>post a code excerpt? > > > >It's a straightforward test program. > > Your assumption, that the address returned from recvfrom(2) should be > correct, seems generally right to me. However, it looks like you may not > be initializing senderLen to the size of senderAddr, which means that the > size getting passed in may be random stack garbage. In which case what you > find in the sockaddr_in might also be random stack garbage, or might be the > address, depending on whether the uninitialized length was long enough to > fit an IP address in. Could you try adding something like: > > senderLen = sizeof(senderAddr); > > before the call to recvfrom(2)? > > Thanks, > > Robert N M Watson > Computer Laboratory > University of Cambridge > -------------------------------- Snip test program --------------- You nailed it! Initializing the length of the sockaddr stucture was the answer. Thanks very much for pointing out the flaw. -- Best regards, Derek Tattersall dlt@mebtel.net dlt666@yahoo.com dtatters@gmail.com