Tom Lane wrote:
Andrew Chernow <a...@esilo.com> writes:
Tom Lane wrote:
BTW, what about the comments in ip.c to the effect that some versions of
AIX fail when getaddrinfo's second argument *is* null?

For starters, it indicates that sin_port is not zero'd properly. That wouldn't matter here since the plan is to manually set the port in this case, since providing it to getaddrinfo is broken.

Hmm ... so actually we could get *rid* of that special case if we added
this one.  Okay, I withdraw the complaint.  We should simply not rely on
getaddrinfo to do anything right at all w.r.t. the port if we are
running on AIX.  Pass NULL for servname and set the port ourselves in
all cases.

                        regards, tom lane


Done.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/
Index: src/backend/libpq/ip.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/libpq/ip.c,v
retrieving revision 1.43
diff -C6 -r1.43 ip.c
*** src/backend/libpq/ip.c      1 Jan 2009 17:23:42 -0000       1.43
--- src/backend/libpq/ip.c      23 Jan 2009 19:14:07 -0000
***************
*** 71,112 ****
  
  #ifdef HAVE_UNIX_SOCKETS
        if (hintp->ai_family == AF_UNIX)
                return getaddrinfo_unix(servname, hintp, result);
  #endif
  
        /* NULL has special meaning to getaddrinfo(). */
        rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
                                         servname, hintp, result);
  
! #ifdef _AIX
  
        /*
         * It seems some versions of AIX's getaddrinfo don't reliably zero
!        * sin_port when servname is NULL, so clean up after it.
         */
!       if (servname == NULL && rc == 0)
        {
                struct addrinfo *addr;
  
                for (addr = *result; addr; addr = addr->ai_next)
                {
                        switch (addr->ai_family)
                        {
                                case AF_INET:
!                                       ((struct sockaddr_in *) 
addr->ai_addr)->sin_port = htons(0);
                                        break;
  #ifdef HAVE_IPV6
                                case AF_INET6:
!                                       ((struct sockaddr_in6 *) 
addr->ai_addr)->sin6_port = htons(0);
                                        break;
  #endif
                        }
                }
        }
! #endif
  
        return rc;
  }
  
  
  /*
--- 71,124 ----
  
  #ifdef HAVE_UNIX_SOCKETS
        if (hintp->ai_family == AF_UNIX)
                return getaddrinfo_unix(servname, hintp, result);
  #endif
  
+ #ifndef _AIX
        /* NULL has special meaning to getaddrinfo(). */
        rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
                                         servname, hintp, result);
  
! #else
!       /* NULL hostname has special meaning to getaddrinfo().  We have to
!        * set servname to NULL because some AIX versions, like 4.3, always
!        * fail with EAI_NODATA if not NULL.
!    */
!       rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
!                                        NULL, hintp, result);
  
        /*
         * It seems some versions of AIX's getaddrinfo don't reliably zero
!        * sin_port when servname is NULL, so clean up after it.  Also,
!        * manually set the port when servname is provided.
         */
!       if(rc == 0)
        {
                struct addrinfo *addr;
+               unsigned short port = 0;
+ 
+               if(servname && *servname)
+                       port = htons((unsigned short)atoi(servname));
  
                for (addr = *result; addr; addr = addr->ai_next)
                {
                        switch (addr->ai_family)
                        {
                                case AF_INET:
!                                       ((struct sockaddr_in *) 
addr->ai_addr)->sin_port = port;
                                        break;
  #ifdef HAVE_IPV6
                                case AF_INET6:
!                                       ((struct sockaddr_in6 *) 
addr->ai_addr)->sin6_port = port;
                                        break;
  #endif
                        }
                }
        }
! #endif /* !_AIX */
  
        return rc;
  }
  
  
  /*
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to