From owner-freebsd-questions@FreeBSD.ORG Thu Mar 13 16:10:02 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 369B61065674 for ; Thu, 13 Mar 2008 16:10:02 +0000 (UTC) (envelope-from af300wsm@gmail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.177]) by mx1.freebsd.org (Postfix) with ESMTP id 084E38FC1D for ; Thu, 13 Mar 2008 16:10:01 +0000 (UTC) (envelope-from af300wsm@gmail.com) Received: by wa-out-1112.google.com with SMTP id k17so4009064waf.3 for ; Thu, 13 Mar 2008 09:10:01 -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:mime-version:content-type:content-transfer-encoding:content-disposition; bh=9ngG140bEVm25GcWPt7Z3mURgpSXw2s+UuMou8T0fBQ=; b=YYoQAKO+0Ebj80Ix3iwbKqN9+rojFNUauuGymcPgY8Sy3QSQwmqmJZxow/OURAqiFqRRHS8T8mQu0yinJyCiirR+CZSWICunqNGIJYTXXmbE5Erpqf9qPVWgEJHrrxI1m+I3o+a5PTNK4m7i63LUlOo/ajwIVFqN4T/8Vm4vZGQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=n6x/dUm4apOQxcYeILI5YakIhpc+R4F4gF/Y/MKXB+kdGSYj7+fNxNAKD5cbDTkODIMWddO+Fc01n9ez4iieuDfJcGwqv+RCAp2XFcTTXqofGaCm9QueH47J68xU54QEpnD4OJq3yf6eKbvrM+msee3sB3apAJ3sWgdS/mqoa2A= Received: by 10.115.88.1 with SMTP id q1mr9708486wal.64.1205424601582; Thu, 13 Mar 2008 09:10:01 -0700 (PDT) Received: by 10.114.191.15 with HTTP; Thu, 13 Mar 2008 09:10:01 -0700 (PDT) Message-ID: <340a29540803130910l2a5badacxe50cd81ace87e1f7@mail.gmail.com> Date: Thu, 13 Mar 2008 10:10:01 -0600 From: "Andrew Falanga" To: "FreeBSD Questions" MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: 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: Thu, 13 Mar 2008 16:10:02 -0000 Hi, I'd like to know why the inet_pton(3) doesn't fill in the address family of the proper structure passed into it. I'm at a complete loss for why. Here's the prototype: int inet_pton(int af, const char * restrict src, void * restrict dst); Three arguments only. The address family, hm, I'm passing it in; the address string in printable ASCII text, and a void pointer to the address structure to put the address into, presumably one of the sockaddr_* family structures for AF_INET or AF_INET6 (further, the man page says that this function is only valid for these two families now anyway). >From some coding for a program, I did find that this function, inet_pton(3), *does* in fact mangle the sin_family member of the sockaddr_in structure, so why not "mangle" it to what it should be? I was doing something like this: // valid code above sockaddr_in sa; sa.sin_family = AF_INET; sa.sin_port = htons(3252); inet_pton(AF_INET, "192.168.0.1", &sa); sendto(sa, msg, strlen(msg), 0, (struct sockaddr*)&sa, sizeof(sa)); The call to sendto is wrapped in an if an was failing for errno code 47, Address family not supported by protocol (I was using UDP). I changed the assignment of AF_INET to the sa.sin_family member to *after* the call to inet_pton(3) and suddenly everything worked. Why? Since the address family was used by inet_pton(3) to figure out how to read the address and assign it to sa.sin_addr.s_addr, why not simply assign AF_INET to the address family member in inet_pton(3)? I'm not trying to be argumentative. I'm just curious. It seems like redundancy. I've used the address family to tell inet_pton(3) how to operate, and then this function can't assign it to the sockaddr_in structure passed to it? This makes little sense. In case it's because I'm using older FBSD libraries that had a flaw fixed, I'm using FreeBSD 6.2-RELEASE-p4. Is this because that's how POSIX defined it to work? Is this the right venue or should I try one of the other mailing lists? Thanks, 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?