]> granicus.if.org Git - postgresql/blobdiff - src/port/getaddrinfo.c
Centralize single quote escaping in src/port/quotes.c
[postgresql] / src / port / getaddrinfo.c
index 51e31c18c06e580678e052f9d1c1430e660af857..e2b59efac86edbd144583f410ffbf711f5582596 100644 (file)
@@ -8,15 +8,15 @@
  * platform, we'll need to split this file and provide a separate configure
  * test for getnameinfo().
  *
- * Windows may or may not have these routines, so we handle Windows special
+ * Windows may or may not have these routines, so we handle Windows specially
  * by dynamically checking for their existence.  If they already exist, we
  * use the Windows native routines, but if not, we use our own.
  *
  *
- * Copyright (c) 2003-2006, PostgreSQL Global Development Group
+ * Copyright (c) 2003-2013, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/port/getaddrinfo.c,v 1.24 2006/06/07 22:24:46 momjian Exp $
+ *       src/port/getaddrinfo.c
  *
  *-------------------------------------------------------------------------
  */
@@ -30,6 +30,7 @@
 #include <arpa/inet.h>
 
 #include "getaddrinfo.h"
+#include "libpq/pqcomm.h"              /* needed for struct sockaddr_storage */
 
 
 #ifdef WIN32
@@ -327,12 +328,10 @@ gai_strerror(int errcode)
                case EAI_MEMORY:
                        return "Not enough memory";
 #endif
-#ifdef EAI_NODATA
-#ifndef WIN32_ONLY_COMPILER    /* MSVC complains because another case has the same value */
+#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME            /* MSVC/WIN64 duplicate */
                case EAI_NODATA:
                        return "No host data of that type was found";
 #endif
-#endif
 #ifdef EAI_SERVICE
                case EAI_SERVICE:
                        return "Class type not found";
@@ -374,11 +373,6 @@ getnameinfo(const struct sockaddr * sa, int salen,
        if (sa == NULL || (node == NULL && service == NULL))
                return EAI_FAIL;
 
-       /* We don't support those. */
-       if ((node && !(flags & NI_NUMERICHOST))
-               || (service && !(flags & NI_NUMERICSERV)))
-               return EAI_FAIL;
-
 #ifdef HAVE_IPV6
        if (sa->sa_family == AF_INET6)
                return EAI_FAMILY;
@@ -386,16 +380,14 @@ getnameinfo(const struct sockaddr * sa, int salen,
 
        if (node)
        {
-               int                     ret = -1;
-
                if (sa->sa_family == AF_INET)
                {
-                       char       *p;
-
-                       p = inet_ntoa(((struct sockaddr_in *) sa)->sin_addr);
-                       ret = snprintf(node, nodelen, "%s", p);
+                       if (inet_net_ntop(AF_INET, &((struct sockaddr_in *) sa)->sin_addr,
+                                                         sa->sa_family == AF_INET ? 32 : 128,
+                                                         node, nodelen) == NULL)
+                               return EAI_MEMORY;
                }
-               if (ret == -1 || ret > nodelen)
+               else
                        return EAI_MEMORY;
        }