pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
use inet_pton() instead of inet_addr() for ipv4/6
2+ messages / 2 participants
[nested] [flat]

* use inet_pton() instead of inet_addr() for ipv4/6
@ 2013-12-06 10:58  Pavel Raiskup <praiskup@redhat.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Pavel Raiskup @ 2013-12-06 10:58 UTC (permalink / raw)
  To: pgsql-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
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: use inet_pton() instead of inet_addr() for ipv4/6
@ 2013-12-10 00:31  Inoue, Hiroshi <inoue@tpf.co.jp>
  parent: Pavel Raiskup <praiskup@redhat.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Inoue, Hiroshi @ 2013-12-10 00:31 UTC (permalink / raw)
  To: Pavel Raiskup <praiskup@redhat.com>; pgsql-odbc

Hi Pavel,

(2013/12/06 19:58), Pavel Raiskup wrote:
> 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!

Thanks for the patch.
I will take care of it.

regards,
Hiroshi Inoue




-- 
I am using the free version of SPAMfighter.
SPAMfighter has removed 1069 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

Do you have a slow PC? Try a Free scan 
http://www.spamfighter.com/SLOW-PCfighter?cid=sigen



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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2013-12-10 00:31 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-12-06 10:58 use inet_pton() instead of inet_addr() for ipv4/6 Pavel Raiskup <praiskup@redhat.com>
2013-12-10 00:31 ` Inoue, Hiroshi <inoue@tpf.co.jp>

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