pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pavel Raiskup <praiskup@redhat.com>
To: pgsql-odbc@postgresql.org <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> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>

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

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

0001-socket-speedup-also-ipv6-connection.patch (text/x-patch, 1.5K) download From e4b8ea0a87eb2f3ce7a9bbb9bcff5d8225a68fce Mon Sep 17 00:00:00 2001 From: Pavel Raiskup <praiskup@redhat.com> 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

view thread (2+ messages)  latest in thread

Message-ID: <3932297.uqAmftHYU6@nb.usersys.redhat.com>
Permalink:  ../3932297.uqAmftHYU6@nb.usersys.redhat.com/
Also on:    postgresql.org/message-id/3932297.uqAmftHYU6@nb.usersys.redhat.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: praiskup@redhat.com
  Subject: Re: use inet_pton() instead of inet_addr() for ipv4/6
  In-Reply-To: <3932297.uqAmftHYU6@nb.usersys.redhat.com>
  References: <3932297.uqAmftHYU6@nb.usersys.redhat.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox