From owner-freebsd-questions@FreeBSD.ORG Fri Mar 14 15:24:01 2008 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 9E5851065671 for ; Fri, 14 Mar 2008 15:24:01 +0000 (UTC) (envelope-from af300wsm@gmail.com) Received: from el-out-1112.google.com (el-out-1112.google.com [209.85.162.180]) by mx1.freebsd.org (Postfix) with ESMTP id 6498D8FC26 for ; Fri, 14 Mar 2008 15:24:01 +0000 (UTC) (envelope-from af300wsm@gmail.com) Received: by el-out-1112.google.com with SMTP id v27so2217170ele.12 for ; Fri, 14 Mar 2008 08:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=++tOw/WlrnKV/5L2XdeRUAEr5k6V5tNNleAIRQcQPpk=; b=s1TjFgdV6dKRu8bJLcXumgIw52L3aFEW9vtBExKZC5nfvZlWxWH8vGrKbeGMKhiNm8DQdzs7HU7sEVTe5vWNPuEvLTUylLnDIvPxaCYzq6KIbBFvBniUGikUxUSIoLBXnsRoO/RPIo57Ff26hUS9tN3Q7sSrHBe3y50+14rmwno= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UIh7zuv5B4SpfHm12pdL0c5OwKt0fkReImI/S3UBp27CHQmpyQn3GaCPCKEC78rDTUbknuX7m0DdrqN3Ki6LVZqIileTCCok0SiJCtpm227429BSp+FZ2ib0GF8CqeiqdNnxWJcUH83ARlvxJnlMZlwRjk168GoM83iEKBDfW98= Received: by 10.114.175.16 with SMTP id x16mr11976276wae.12.1205508239606; Fri, 14 Mar 2008 08:23:59 -0700 (PDT) Received: by 10.114.191.15 with HTTP; Fri, 14 Mar 2008 08:23:59 -0700 (PDT) Message-ID: <340a29540803140823n6f838fdaj7692571f69003fb5@mail.gmail.com> Date: Fri, 14 Mar 2008 09:23:59 -0600 From: "Andrew Falanga" To: "Patrick Mahan" In-Reply-To: <47DA13AF.5090804@mahan.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <340a29540803130910l2a5badacxe50cd81ace87e1f7@mail.gmail.com> <47D9682B.5060402@mahan.org> <340a29540803131111g20315740n629ee146bc2f8602@mail.gmail.com> <47DA13AF.5090804@mahan.org> Cc: FreeBSD Questions Subject: Re: Network programming question 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: Fri, 14 Mar 2008 15:24:01 -0000 On Thu, Mar 13, 2008 at 11:57 PM, Patrick Mahan wrote: > > > > inet_pton() clobbered the fields you pointed out. In fact the sin_family > field was being set to 0x01 which caused your initial EADDRNOTSUPPORT error > you were seeing. You quick change fixed that problem. However, (depending > on how sockaddr_in structure is actually allocated) the sin_addr field was > 0.0.0.0. This is actually an accepted form of the broadcast address for UDP > packets. I forget exactly who the culprit was (Sun comes to mind) but there > was a need to allow broadcasts to 0.0.0.0 (which is also know as INADDR_ANY). > So, therefore, sendto() succeeded, just not in the way you expected. Looking > at in_pcbconnect_setup() in the kernel shows that actually the packet is sent > to the local primary interface address. > > Let's look at what really happen to that packet - > > "192.168.0.1" after being mangled by inet_pton() gives > the field sin_addr.s_addr of 0x0100A8C0. This should make > your sockaddr_in structure look like - > > sa.sin_len = 0x01 > sa.sin_family = 0x00 > sa.sin_port = 0xA8C0 (which is port 49320) > sa.sin_addr.s_addr = 0x00000000 > > So the sendto() call was sending a packet to your local interface for port 49320. > And since UDP is a connectionless protocol, you don't have a way (unless it is > builtin to your application protocol) to determine an error. For example, TFTP > sends back notification for every dgram received. > > I hope this helps with your understanding. I highly recommend if you are going > to do more network programming that you obtain at least some books on the subject. > > > Patrick > Thanks much for this explanation. Books would be good, yes. I guys got to learn somehow. Thanks for taking the time to explain it. That's interesting that a broadcast may be sent to 0.0.0.0. I knew that 0.0.0.0 is equal to INADDR_ANY. However, I thought it wasn't possible to send to that address, only to bind to it locally for a server application. Andy -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?