Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 50063 invoked from network); 7 Mar 2007 10:16:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Mar 2007 10:16:46 -0000 Received: (qmail 31473 invoked by uid 500); 7 Mar 2007 10:16:53 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 31424 invoked by uid 500); 7 Mar 2007 10:16:53 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 31412 invoked by uid 99); 7 Mar 2007 10:16:52 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2007 02:16:52 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of lucian.grijincu@avira.com designates 81.12.221.100 as permitted sender) Received: from [81.12.221.100] (HELO passage.avira.com) (81.12.221.100) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2007 02:16:43 -0800 Received: by passage.avira.com (Postfix/AVIRA, from userid 26) id 4B31E12494E; Wed, 7 Mar 2007 12:16:21 +0200 (EET) X-Spam-Checker-Version: SpamAssassin 3.1.8-gr0 (2007-02-13) on passage.avira.com X-Spam-Level: Received: from localhost (localhost [127.0.0.1]) by passage.avira.com (Postfix/AVIRA) with ESMTP id 8684612494C for ; Wed, 7 Mar 2007 12:16:20 +0200 (EET) Received: from passage.avira.com (localhost [127.0.0.1]) by localhost (AvMailGate-2.0.5-5) id 12512-27BD68FF; Wed, 07 Mar 2007 12:16:20 +0200 Received: from naliboat.bu.avira.com (dasapass.avira.com [81.12.221.98]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mail.avira.local", Issuer "AVIRA Registration Authority" (verified OK)) by passage.avira.com (Postfix/AVIRA) with ESMTP id 780D912494C for ; Wed, 7 Mar 2007 12:16:20 +0200 (EET) Received: (qmail 15419 invoked from network); 7 Mar 2007 10:16:20 -0000 Received: from lgrijincu.bu.avira.com (HELO ?10.2.1.20?) (10.2.1.20) by naliboat.bu.avira.com with (DHE-RSA-AES256-SHA encrypted) SMTP; 7 Mar 2007 10:16:20 -0000 Message-ID: <45EE9277.60408@avira.com> Date: Wed, 07 Mar 2007 12:22:47 +0200 From: Lucian Adrian Grijincu User-Agent: Thunderbird 1.5.0.9 (X11/20070103) MIME-Version: 1.0 To: dev@apr.apache.org Subject: [Tip of the Day] getaddrinfo is not just for IPv6 X-Enigmail-Version: 0.94.0.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig8D7CF2BBD3D088224F286BF2" X-AntiVirus: checked by AntiVir MailGate (version: 2.0.5-5; AVE: 7.3.1.38; VDF: 6.38.0.11; host: passage.avira.com) X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=-2.4 required=4.0 tests=AWL,BAYES_00 autolearn=ham version=3.1.8-gr0 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig8D7CF2BBD3D088224F286BF2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable =46rom http://udrepper.livejournal.com/16116.html : /*getaddrinfo is not just for IPv6*/ I've heard far too often that getaddrinfo is only interesting for IPv6 and therefore can be ignored since one does not have IPv6. Aside from the fact that all programs should be protocol independent this statement is bogus. gethostbyname etc do not perform correctly in some situations where only ever IPv4 is involved. Assume you have an internal IPv4 network with, say, 192.168.x.y addresses. In addition you have a server (web server, for instance) which is also visible on the Internet. This server has two addresses: one 192.168.x.y address and one global address. The client is a NATed machine on the intranet. Now what happens if the nameserver returns both addresses to a query for the addresses of said server? With gethostbyname the addresses are returned to the caller in the order they are received from the DNS server. Maybe some randomization is applied. In short, it is possible that the internal machine gets sees the public IPv4 address and then connects to it. This is not only wasteful (the request has to be routed through a switch), it might even be dangerous (the traffic might actually have to go through the Internet). With getaddrinfo this is not the case. The sorting according to RFC 3484 makes sure that the internal address of the server is returned first. The sorting function will notice that the source address used on the client is also an internal address and therefore the internal address of the server is a better match than the global address. In summary, gethostbyaddr is not only about IPv6. The old interfaces were simply completely inadequate and should never be used. If you /still/ haven't converted your programs to use getaddrinfo instead of gethostbyname and gethostbyname2 do it now. I have written some time ago a brief intro . --=20 Best regards, Lucian Adrian Grijincu Software Developer Avira Soft srl lucian.grijincu@avira.com http://www.avira.com ----------------------------------------------------------- DISCLAIMER: This message is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone. ----------------------------------------------------------- --------------enig8D7CF2BBD3D088224F286BF2 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFF7pJ3i7jKZYXhmrMRAl10AJ47T7HhgYDbpqMutvDKP4Qm4lZQcQCfb6tO 2KPj1oJEaJKHSkfh9qyGlEw= =St30 -----END PGP SIGNATURE----- --------------enig8D7CF2BBD3D088224F286BF2--