From owner-freebsd-net@FreeBSD.ORG Tue Apr 27 11:48:32 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E1C2B16A4CE for ; Tue, 27 Apr 2004 11:48:32 -0700 (PDT) Received: from smtpout.mac.com (smtpout.mac.com [17.250.248.88]) by mx1.FreeBSD.org (Postfix) with ESMTP id C65E543D31 for ; Tue, 27 Apr 2004 11:48:32 -0700 (PDT) (envelope-from cswiger@mac.com) Received: from mac.com (smtpin01-en2 [10.13.10.146]) by smtpout.mac.com (Xserve/MantshX 2.0) with ESMTP id i3RImWog014213; Tue, 27 Apr 2004 11:48:32 -0700 (PDT) Received: from [10.1.1.193] (nfw2.codefab.com [199.103.21.225] (may be forged)) (authenticated bits=0)i3RImVgQ023177; Tue, 27 Apr 2004 11:48:31 -0700 (PDT) In-Reply-To: <20040427160901.GA2552@laptop.6bone.nl> References: <20040427160901.GA2552@laptop.6bone.nl> Mime-Version: 1.0 (Apple Message framework v613) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <773BE796-987B-11D8-ABA7-003065ABFD92@mac.com> Content-Transfer-Encoding: 7bit From: Charles Swiger Date: Tue, 27 Apr 2004 14:48:25 -0400 To: Mark Santcroos X-Mailer: Apple Mail (2.613) cc: net@freebsd.org Subject: Re: udp checksum on raw sockets X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.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: Tue, 27 Apr 2004 18:48:33 -0000 On Apr 27, 2004, at 12:09 PM, Mark Santcroos wrote: > * I'm sending UDP packets on a raw socket. > > * iphdr->ip_src.s_addr = INADDR_ANY; > So I don't know the IP address that will be used as src address. The kernel ought to pick the src address of the interface the packet will be sent from according to the routing table. At least if you were using SOCK_DGRAM, I'm not sure how much the kernel fills in when using SOCK_RAW. > So as far as I can see, I have a problem generating the checksum in > userspace. > > Suggestion: > > Would it make sense that if: > sysctl net.udp.checksum=1 > and > udphdr->uh_sum = 0; > in a UDP packet created on a raw socket, to do the checksum in the > kernel > instead of leaving it zero? If it does, I can create a patch. And likewise with computing the checksum, I would expect the kernel to compute the packet checksums-- there's ip_sum as well as uh_sum. > Any other hints as how to do the checksum in userland are welcome too. > As > that is the "ultimate" problem I try to fix. Consider using libnet to build your packets: http://www.packetfactory.net/projects/libnet/ ...between libnet and libpcap, you've got userland code to handle both sending and receiving packets in an OS-independent fashion. Amoung other things, libnet has an implementation of "how to compute packet checksums" available for you to consider or use. -- -Chuck