* 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-2005, PostgreSQL Global Development Group
+ * Copyright (c) 2003-2013, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/getaddrinfo.c,v 1.21 2005/10/15 02:49:51 momjian Exp $
+ * src/port/getaddrinfo.c
*
*-------------------------------------------------------------------------
*/
/* This is intended to be used in both frontend and backend, so use c.h */
#include "c.h"
-#ifndef WIN32_CLIENT_ONLY
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#endif
#include "getaddrinfo.h"
+#include "libpq/pqcomm.h" /* needed for struct sockaddr_storage */
#ifdef WIN32
-
-#define WIN32_LEAN_AND_MEAN
-
-#include <windows.h>
-
/*
* The native routines may or may not exist on the Windows platform we are on,
* so we dynamically look up the routines, and call them via function pointers.
case EAI_MEMORY:
return "Not enough memory";
#endif
-#ifdef EAI_NODATA
+#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME /* MSVC/WIN64 duplicate */
case EAI_NODATA:
return "No host data of that type was found";
#endif
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;
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;
}