Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vot6w-0000Xr-7n for pgsql-odbc@arkaria.postgresql.org; Fri, 06 Dec 2013 10:58:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vot6v-000726-Ki for pgsql-odbc@arkaria.postgresql.org; Fri, 06 Dec 2013 10:58:17 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vot6u-000720-WF for pgsql-odbc@postgresql.org; Fri, 06 Dec 2013 10:58:17 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vot6r-00046W-87 for pgsql-odbc@postgresql.org; Fri, 06 Dec 2013 10:58:16 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rB6AwBcb000938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 6 Dec 2013 05:58:12 -0500 Received: from nb.usersys.redhat.com (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rB6AwBb0011559 for ; Fri, 6 Dec 2013 05:58:11 -0500 From: Pavel Raiskup To: "pgsql-odbc@postgresql.org" Subject: use inet_pton() instead of inet_addr() for ipv4/6 Date: Fri, 06 Dec 2013 11:58:10 +0100 Message-ID: <3932297.uqAmftHYU6@nb.usersys.redhat.com> Organization: Red Hat User-Agent: KMail/4.11.3 (Linux/3.11.9-300.fc20.x86_64; KDE/4.11.3; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2772144.tcsS3xzEd9" Content-Transfer-Encoding: 7Bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Pg-Spam-Score: -5.2 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org This is a multi-part message in MIME format. --nextPart2772144.tcsS3xzEd9 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Hi, our regular package checking discovered that in postgresql-odbc is using inet_addr() call (which is not ipv6 compliant). I tried to look at it and it was used just for parsing of ipv4 addresses. It is not a big deal (the worst thing what can happen is that ipv6 addresses will cost a little bit more time to be resolved). Better solution would be imo to use inet_pton() call for both ipv4 and ipv6 address families. Patch is attached, any comment is welcome! Pavel --nextPart2772144.tcsS3xzEd9 Content-Disposition: attachment; filename="0001-socket-speedup-also-ipv6-connection.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-socket-speedup-also-ipv6-connection.patch" From e4b8ea0a87eb2f3ce7a9bbb9bcff5d8225a68fce Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Thu, 5 Dec 2013 13:58:30 +0100 Subject: [PATCH] socket: speedup also ipv6 connection Call getaddrinfo() with AI_NUMERICHOST if it is ipv4/ipv6 address. For that reason the inet_pton() is better than inet_addr(). --- socket.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/socket.c b/socket.c index da574e2..01ea56c 100644 --- a/socket.c +++ b/socket.c @@ -230,7 +230,15 @@ static BOOL format_sockerr(char *errmsg, size_t buflen, int errnum, const char * snprintf(errmsg, buflen, "%s failed for [%s:%d] ", cmd, host, portno); return ret; } - + +static int +is_numeric_address(const char *hostname) +{ + char unused[16]; + return (inet_pton(AF_INET, hostname, &unused) || + inet_pton(AF_INET6, hostname, &unused)); +} + char SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname, long timeout) { @@ -271,8 +279,9 @@ SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname, long tim rest.ai_socktype = SOCK_STREAM; rest.ai_family = AF_UNSPEC; snprintf(portstr, sizeof(portstr), "%d", port); - if (inet_addr(hostname) != INADDR_NONE) - rest.ai_flags |= AI_NUMERICHOST; + if (is_numeric_address(hostname)) + /* don't resolve address in getaddrinfo() if not necessary */ + rest.ai_flags |= AI_NUMERICHOST; ret = getaddrinfo_ptr(hostname, portstr, &rest, &addrs); if (ret || !addrs) { -- 1.8.4.2 --nextPart2772144.tcsS3xzEd9 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --nextPart2772144.tcsS3xzEd9--