On Fri, Aug 12, 2022 at 8:03 PM Thomas Munro <thomas.mu...@gmail.com> wrote:
> On Fri, Aug 12, 2022 at 7:15 PM Peter Eisentraut
> <peter.eisentr...@enterprisedb.com> wrote:
> > But maybe it would be better to make that a separate patch from the
> > sys/un.h configure changes, just so there is more clarity around it.
>
> Cool, I'll do that.

I pushed these, except I chopped out the HAVE_UNIX_SOCKETS part as
requested.  Here it is in a separate patch, with a commit message that
explains the rationale (essentially, what you said, it's basically a
runtime matter for a hypothetical AF_UNIX-less system to complain
about).  Tom, does this argument persuade you?  Also, a couple of
nearby things:

  Remove HAVE_UNIX_SOCKETS.
  Remove configure probe for struct sockaddr_storage.
  Remove configure probe for getaddrinfo, and replacement code.

If I'm reading comments and scraped configure data right, it looks
like those last two things were there only for HP-UX 10 and Windows <
8.1.

I tried to figure out how to get rid of
PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS, but there we're into genuine
non-standard cross-platform differences.  At best maybe you could
maybe skip the test for ss_family (POSIX says you have to have that,
but I haven't read RFC 2553 to see why it claims someone should spell
it differently).  Didn't seem worth changing.

bfbot=> select name, value, count(*) from macro where name like
'%SOCKADDR_%' group by 1, 2;
                  name                  | value | count
----------------------------------------+-------+-------
 HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN    | 1     |    13 <-- BSDish
 HAVE_STRUCT_SOCKADDR_STORAGE           | 1     |   108 <-- everyone
 HAVE_STRUCT_SOCKADDR_SA_LEN            | 1     |    18 <-- BSDish + AIX
 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY | 1     |   108 <-- everyone
 HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN  | 1     |     5 <-- AIX
 HAVE_STRUCT_SOCKADDR_UN                | 1     |   106 <-- everyone
except mingw
(6 rows)
From 87c1b8dff6dea44f6ef920b0b02386e5e2b68be4 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.mu...@gmail.com>
Date: Thu, 11 Aug 2022 15:30:38 +1200
Subject: [PATCH 1/3] Remove HAVE_UNIX_SOCKETS.

Since HAVE_UNIX_SOCKETS is now defined unconditionally, remove the macro
and drop a small amount of dead code.

The last known systems not to have them (as far as I know at least) were
QNX, which we de-supported years ago, and Windows, which now has them.

If a hypothetical new OS shows up with the POSIX sockets API but without
working AF_UNIX, it'll presumably still be able to compile the code, and
fail at runtime with unsupported address family.  We might want to
consider adding a HINT that you should turn it off if your OS doesn't
support it at that point, but it doesn't seem worth making the relevant
code compile-time conditional.

Reviewed-by: Peter Eisentraut <peter.eisentr...@enterprisedb.com>
Reviewed-by: Tom Lane <t...@sss.pgh.pa.us>
Reviewed-by: Andres Freund <and...@anarazel.de>
Discussion: https://postgr.es/m/CA%2BhUKG%2BL_3brvh%3D8e0BW_VfX9h7MtwgN%3DnFHP5o7X2oZucY9dg%40mail.gmail.com
---
 src/backend/libpq/hba.c             | 10 -------
 src/backend/libpq/pqcomm.c          | 18 -------------
 src/backend/postmaster/postmaster.c |  2 --
 src/backend/utils/misc/guc.c        |  4 ---
 src/bin/initdb/initdb.c             | 41 -----------------------------
 src/bin/pg_upgrade/option.c         |  4 +--
 src/bin/pg_upgrade/server.c         |  2 +-
 src/common/ip.c                     | 11 --------
 src/include/port.h                  |  3 ---
 src/interfaces/libpq/fe-connect.c   | 12 ---------
 src/test/regress/pg_regress.c       | 19 ++-----------
 11 files changed, 5 insertions(+), 121 deletions(-)

diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index deee05c197..66f2156cde 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -973,17 +973,7 @@ parse_hba_line(TokenizedAuthLine *tok_line, int elevel)
 	token = linitial(tokens);
 	if (strcmp(token->string, "local") == 0)
 	{
-#ifdef HAVE_UNIX_SOCKETS
 		parsedline->conntype = ctLocal;
-#else
-		ereport(elevel,
-				(errcode(ERRCODE_CONFIG_FILE_ERROR),
-				 errmsg("local connections are not supported by this build"),
-				 errcontext("line %d of configuration file \"%s\"",
-							line_num, HbaFileName)));
-		*err_msg = "local connections are not supported by this build";
-		return NULL;
-#endif
 	}
 	else if (strcmp(token->string, "host") == 0 ||
 			 strcmp(token->string, "hostssl") == 0 ||
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 75392a8bb7..3ec4328613 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -149,10 +149,8 @@ static void socket_putmessage_noblock(char msgtype, const char *s, size_t len);
 static int	internal_putbytes(const char *s, size_t len);
 static int	internal_flush(void);
 
-#ifdef HAVE_UNIX_SOCKETS
 static int	Lock_AF_UNIX(const char *unixSocketDir, const char *unixSocketPath);
 static int	Setup_AF_UNIX(const char *sock_path);
-#endif							/* HAVE_UNIX_SOCKETS */
 
 static const PQcommMethods PqCommSocketMethods = {
 	socket_comm_reset,
@@ -334,10 +332,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 	struct addrinfo hint;
 	int			listen_index = 0;
 	int			added = 0;
-
-#ifdef HAVE_UNIX_SOCKETS
 	char		unixSocketPath[MAXPGPATH];
-#endif
 #if !defined(WIN32) || defined(IPV6_V6ONLY)
 	int			one = 1;
 #endif
@@ -348,7 +343,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 	hint.ai_flags = AI_PASSIVE;
 	hint.ai_socktype = SOCK_STREAM;
 
-#ifdef HAVE_UNIX_SOCKETS
 	if (family == AF_UNIX)
 	{
 		/*
@@ -369,7 +363,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 		service = unixSocketPath;
 	}
 	else
-#endif							/* HAVE_UNIX_SOCKETS */
 	{
 		snprintf(portNumberStr, sizeof(portNumberStr), "%d", portNumber);
 		service = portNumberStr;
@@ -427,11 +420,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 				familyDesc = _("IPv6");
 				break;
 #endif
-#ifdef HAVE_UNIX_SOCKETS
 			case AF_UNIX:
 				familyDesc = _("Unix");
 				break;
-#endif
 			default:
 				snprintf(familyDescBuf, sizeof(familyDescBuf),
 						 _("unrecognized address family %d"),
@@ -441,11 +432,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 		}
 
 		/* set up text form of address for log messages */
-#ifdef HAVE_UNIX_SOCKETS
 		if (addr->ai_family == AF_UNIX)
 			addrDesc = unixSocketPath;
 		else
-#endif
 		{
 			pg_getnameinfo_all((const struct sockaddr_storage *) addr->ai_addr,
 							   addr->ai_addrlen,
@@ -540,7 +529,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 			continue;
 		}
 
-#ifdef HAVE_UNIX_SOCKETS
 		if (addr->ai_family == AF_UNIX)
 		{
 			if (Setup_AF_UNIX(service) != STATUS_OK)
@@ -549,7 +537,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 				break;
 			}
 		}
-#endif
 
 		/*
 		 * Select appropriate accept-queue length limit.  PG_SOMAXCONN is only
@@ -572,13 +559,11 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 			continue;
 		}
 
-#ifdef HAVE_UNIX_SOCKETS
 		if (addr->ai_family == AF_UNIX)
 			ereport(LOG,
 					(errmsg("listening on Unix socket \"%s\"",
 							addrDesc)));
 		else
-#endif
 			ereport(LOG,
 			/* translator: first %s is IPv4 or IPv6 */
 					(errmsg("listening on %s address \"%s\", port %d",
@@ -597,8 +582,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 }
 
 
-#ifdef HAVE_UNIX_SOCKETS
-
 /*
  * Lock_AF_UNIX -- configure unix socket file path
  */
@@ -699,7 +682,6 @@ Setup_AF_UNIX(const char *sock_path)
 	}
 	return STATUS_OK;
 }
-#endif							/* HAVE_UNIX_SOCKETS */
 
 
 /*
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 227bd9891e..8a038d1b2a 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -1297,7 +1297,6 @@ PostmasterMain(int argc, char *argv[])
 	}
 #endif
 
-#ifdef HAVE_UNIX_SOCKETS
 	if (Unix_socket_directories)
 	{
 		char	   *rawstring;
@@ -1347,7 +1346,6 @@ PostmasterMain(int argc, char *argv[])
 		list_free_deep(elemlist);
 		pfree(rawstring);
 	}
-#endif
 
 	/*
 	 * check that we have some socket to listen on
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 5db5df6285..9fbbfb1be5 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -4452,11 +4452,7 @@ static struct config_string ConfigureNamesString[] =
 			GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
 		},
 		&Unix_socket_directories,
-#ifdef HAVE_UNIX_SOCKETS
 		DEFAULT_PGSOCKET_DIR,
-#else
-		"",
-#endif
 		NULL, NULL, NULL
 	},
 
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 2c93ffe811..4feb5db3fa 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -242,9 +242,6 @@ static char backend_exec[MAXPGPATH];
 static char **replace_token(char **lines,
 							const char *token, const char *replacement);
 
-#ifndef HAVE_UNIX_SOCKETS
-static char **filter_lines_with_token(char **lines, const char *token);
-#endif
 static char **readfile(const char *path);
 static void writefile(char *path, char **lines);
 static FILE *popen_check(const char *command, const char *mode);
@@ -418,36 +415,6 @@ replace_token(char **lines, const char *token, const char *replacement)
 	return result;
 }
 
-/*
- * make a copy of lines without any that contain the token
- *
- * a sort of poor man's grep -v
- */
-#ifndef HAVE_UNIX_SOCKETS
-static char **
-filter_lines_with_token(char **lines, const char *token)
-{
-	int			numlines = 1;
-	int			i,
-				src,
-				dst;
-	char	  **result;
-
-	for (i = 0; lines[i]; i++)
-		numlines++;
-
-	result = (char **) pg_malloc(numlines * sizeof(char *));
-
-	for (src = 0, dst = 0; src < numlines; src++)
-	{
-		if (lines[src] == NULL || strstr(lines[src], token) == NULL)
-			result[dst++] = lines[src];
-	}
-
-	return result;
-}
-#endif
-
 /*
  * get the lines from a text file
  */
@@ -1045,12 +1012,8 @@ setup_config(void)
 				 n_buffers * (BLCKSZ / 1024));
 	conflines = replace_token(conflines, "#shared_buffers = 128MB", repltok);
 
-#ifdef HAVE_UNIX_SOCKETS
 	snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",
 			 DEFAULT_PGSOCKET_DIR);
-#else
-	snprintf(repltok, sizeof(repltok), "#unix_socket_directories = ''");
-#endif
 	conflines = replace_token(conflines, "#unix_socket_directories = '/tmp'",
 							  repltok);
 
@@ -1210,11 +1173,7 @@ setup_config(void)
 
 	conflines = readfile(hba_file);
 
-#ifndef HAVE_UNIX_SOCKETS
-	conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");
-#else
 	conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
-#endif
 
 #ifdef HAVE_IPV6
 
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index 0954b75ec0..fbab1c4fb7 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -444,7 +444,7 @@ adjust_data_dir(ClusterInfo *cluster)
 void
 get_sock_dir(ClusterInfo *cluster, bool live_check)
 {
-#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
+#if !defined(WIN32)
 	if (!live_check)
 		cluster->sockdir = user_opts.socketdir;
 	else
@@ -490,7 +490,7 @@ get_sock_dir(ClusterInfo *cluster, bool live_check)
 			pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu",
 				   orig_port, cluster->port);
 	}
-#else							/* !HAVE_UNIX_SOCKETS || WIN32 */
+#else							/* WIN32 */
 	cluster->sockdir = NULL;
 #endif
 }
diff --git a/src/bin/pg_upgrade/server.c b/src/bin/pg_upgrade/server.c
index 79479edc0e..9a1a20fb27 100644
--- a/src/bin/pg_upgrade/server.c
+++ b/src/bin/pg_upgrade/server.c
@@ -212,7 +212,7 @@ start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error)
 
 	socket_string[0] = '\0';
 
-#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32)
+#if !defined(WIN32)
 	/* prevent TCP/IP connections, restrict socket access */
 	strcat(socket_string,
 		   " -c listen_addresses='' -c unix_socket_permissions=0700");
diff --git a/src/common/ip.c b/src/common/ip.c
index 267103efb9..dd9193feb1 100644
--- a/src/common/ip.c
+++ b/src/common/ip.c
@@ -38,7 +38,6 @@
 
 
 
-#ifdef	HAVE_UNIX_SOCKETS
 static int	getaddrinfo_unix(const char *path,
 							 const struct addrinfo *hintsp,
 							 struct addrinfo **result);
@@ -47,7 +46,6 @@ static int	getnameinfo_unix(const struct sockaddr_un *sa, int salen,
 							 char *node, int nodelen,
 							 char *service, int servicelen,
 							 int flags);
-#endif
 
 
 /*
@@ -62,10 +60,8 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
 	/* not all versions of getaddrinfo() zero *result on failure */
 	*result = NULL;
 
-#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,
@@ -87,7 +83,6 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
 void
 pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
 {
-#ifdef HAVE_UNIX_SOCKETS
 	if (hint_ai_family == AF_UNIX)
 	{
 		/* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
@@ -101,7 +96,6 @@ pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
 		}
 	}
 	else
-#endif							/* HAVE_UNIX_SOCKETS */
 	{
 		/* struct was built by getaddrinfo() */
 		if (ai != NULL)
@@ -126,14 +120,12 @@ pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
 {
 	int			rc;
 
-#ifdef HAVE_UNIX_SOCKETS
 	if (addr && addr->ss_family == AF_UNIX)
 		rc = getnameinfo_unix((const struct sockaddr_un *) addr, salen,
 							  node, nodelen,
 							  service, servicelen,
 							  flags);
 	else
-#endif
 		rc = getnameinfo((const struct sockaddr *) addr, salen,
 						 node, nodelen,
 						 service, servicelen,
@@ -151,8 +143,6 @@ pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
 }
 
 
-#if defined(HAVE_UNIX_SOCKETS)
-
 /* -------
  *	getaddrinfo_unix - get unix socket info using IPv6-compatible API
  *
@@ -286,4 +276,3 @@ getnameinfo_unix(const struct sockaddr_un *sa, int salen,
 
 	return 0;
 }
-#endif							/* HAVE_UNIX_SOCKETS */
diff --git a/src/include/port.h b/src/include/port.h
index 80dcfb7dfe..cec41eae71 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -503,7 +503,4 @@ extern bool wait_result_is_any_signal(int exit_status, bool include_command_not_
 #define HAVE_SYMLINK 1
 #endif
 
-/* Interfaces that we assume that all systems have. */
-#define HAVE_UNIX_SOCKETS 1
-
 #endif							/* PG_PORT_H */
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index dc49387d6c..730e79a31d 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -1102,10 +1102,8 @@ connectOptions2(PGconn *conn)
 		else if (ch->host != NULL && ch->host[0] != '\0')
 		{
 			ch->type = CHT_HOST_NAME;
-#ifdef HAVE_UNIX_SOCKETS
 			if (is_unixsock_path(ch->host))
 				ch->type = CHT_UNIX_SOCKET;
-#endif
 		}
 		else
 		{
@@ -1115,14 +1113,12 @@ connectOptions2(PGconn *conn)
 			 * This bit selects the default host location.  If you change
 			 * this, see also pg_regress.
 			 */
-#ifdef HAVE_UNIX_SOCKETS
 			if (DEFAULT_PGSOCKET_DIR[0])
 			{
 				ch->host = strdup(DEFAULT_PGSOCKET_DIR);
 				ch->type = CHT_UNIX_SOCKET;
 			}
 			else
-#endif
 			{
 				ch->host = strdup(DefaultHost);
 				ch->type = CHT_HOST_NAME;
@@ -1684,7 +1680,6 @@ getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
 static void
 emitHostIdentityInfo(PGconn *conn, const char *host_addr)
 {
-#ifdef HAVE_UNIX_SOCKETS
 	if (conn->raddr.addr.ss_family == AF_UNIX)
 	{
 		char		service[NI_MAXHOST];
@@ -1698,7 +1693,6 @@ emitHostIdentityInfo(PGconn *conn, const char *host_addr)
 						  service);
 	}
 	else
-#endif							/* HAVE_UNIX_SOCKETS */
 	{
 		const char *displayed_host;
 		const char *displayed_port;
@@ -1748,12 +1742,10 @@ connectFailureMessage(PGconn *conn, int errorno)
 					  "%s\n",
 					  SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)));
 
-#ifdef HAVE_UNIX_SOCKETS
 	if (conn->raddr.addr.ss_family == AF_UNIX)
 		appendPQExpBufferStr(&conn->errorMessage,
 							 libpq_gettext("\tIs the server running locally and accepting connections on that socket?\n"));
 	else
-#endif
 		appendPQExpBufferStr(&conn->errorMessage,
 							 libpq_gettext("\tIs the server running on that host and accepting TCP/IP connections?\n"));
 }
@@ -2415,7 +2407,6 @@ keep_going:						/* We will come back to here until there is
 				break;
 
 			case CHT_UNIX_SOCKET:
-#ifdef HAVE_UNIX_SOCKETS
 				conn->addrlist_family = hint.ai_family = AF_UNIX;
 				UNIXSOCK_PATH(portstr, thisport, ch->host);
 				if (strlen(portstr) >= UNIXSOCK_PATH_BUFLEN)
@@ -2440,9 +2431,6 @@ keep_going:						/* We will come back to here until there is
 									  portstr, gai_strerror(ret));
 					goto keep_going;
 				}
-#else
-				Assert(false);
-#endif
 				break;
 		}
 
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index e015a11c21..cd5a5fd5dd 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -99,11 +99,9 @@ static char *logfilename;
 static FILE *logfile;
 static char *difffilename;
 static const char *sockdir;
-#ifdef HAVE_UNIX_SOCKETS
 static const char *temp_sockdir;
 static char sockself[MAXPGPATH];
 static char socklock[MAXPGPATH];
-#endif
 
 static _resultmap *resultmap = NULL;
 
@@ -285,7 +283,6 @@ stop_postmaster(void)
 	}
 }
 
-#ifdef HAVE_UNIX_SOCKETS
 /*
  * Remove the socket temporary directory.  pg_regress never waits for a
  * postmaster exit, so it is indeterminate whether the postmaster has yet to
@@ -360,7 +357,6 @@ make_temp_sockdir(void)
 
 	return temp_sockdir;
 }
-#endif							/* HAVE_UNIX_SOCKETS */
 
 /*
  * Check whether string matches pattern
@@ -683,7 +679,6 @@ initialize_environment(void)
 		/* PGPORT, see below */
 		/* PGHOST, see below */
 
-#ifdef HAVE_UNIX_SOCKETS
 		if (hostname != NULL)
 			setenv("PGHOST", hostname, 1);
 		else
@@ -693,10 +688,6 @@ initialize_environment(void)
 				sockdir = make_temp_sockdir();
 			setenv("PGHOST", sockdir, 1);
 		}
-#else
-		Assert(hostname != NULL);
-		setenv("PGHOST", hostname, 1);
-#endif
 		unsetenv("PGHOSTADDR");
 		if (port != -1)
 		{
@@ -746,11 +737,9 @@ initialize_environment(void)
 		if (!pghost)
 		{
 			/* Keep this bit in sync with libpq's default host location: */
-#ifdef HAVE_UNIX_SOCKETS
 			if (DEFAULT_PGSOCKET_DIR[0])
 				 /* do nothing, we'll print "Unix socket" below */ ;
 			else
-#endif
 				pghost = "localhost";	/* DefaultHost in fe-connect.c */
 		}
 
@@ -2068,9 +2057,7 @@ regression_main(int argc, char *argv[],
 
 	atexit(stop_postmaster);
 
-#if !defined(HAVE_UNIX_SOCKETS)
-	use_unix_sockets = false;
-#elif defined(WIN32)
+#if defined(WIN32)
 
 	/*
 	 * We don't use Unix-domain sockets on Windows by default, even if the
@@ -2209,7 +2196,7 @@ regression_main(int argc, char *argv[],
 		/*
 		 * To reduce chances of interference with parallel installations, use
 		 * a port number starting in the private range (49152-65535)
-		 * calculated from the version number.  This aids !HAVE_UNIX_SOCKETS
+		 * calculated from the version number.  This aids non-Unix socket mode
 		 * systems; elsewhere, the use of a private socket directory already
 		 * prevents interference.
 		 */
@@ -2329,8 +2316,6 @@ regression_main(int argc, char *argv[],
 			snprintf(buf, sizeof(buf), "%s/data", temp_instance);
 			config_sspi_auth(buf, NULL);
 		}
-#elif !defined(HAVE_UNIX_SOCKETS)
-#error Platform has no means to secure the test installation.
 #endif
 
 		/*
-- 
2.30.2

From 05f16ae2e21704cea6c560c4f333bff555222fa0 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.mu...@gmail.com>
Date: Sat, 13 Aug 2022 21:10:39 +1200
Subject: [PATCH 2/3] Remove configure probe for struct sockaddr_storage.

<sys/socket.h> provides sockaddr_storage in SUSv3.  Windows has it too.
---
 config/c-library.m4        | 14 +-------------
 configure                  | 13 -------------
 configure.ac               |  1 -
 src/include/libpq/pqcomm.h | 23 -----------------------
 src/include/pg_config.h.in |  3 ---
 src/tools/msvc/Solution.pm |  1 -
 6 files changed, 1 insertion(+), 54 deletions(-)

diff --git a/config/c-library.m4 b/config/c-library.m4
index f6b171d923..7a79033730 100644
--- a/config/c-library.m4
+++ b/config/c-library.m4
@@ -73,23 +73,11 @@ AC_DEFUN([PGAC_UNION_SEMUN],
 ])])# PGAC_UNION_SEMUN
 
 
-# PGAC_STRUCT_SOCKADDR_STORAGE
-# ----------------------------
-# If `struct sockaddr_storage' exists, define HAVE_STRUCT_SOCKADDR_STORAGE.
-# If it is missing then one could define it.
-AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE],
-[AC_CHECK_TYPES([struct sockaddr_storage], [], [],
-[#include <sys/types.h>
-#include <sys/socket.h>
-])])# PGAC_STRUCT_SOCKADDR_STORAGE
-
 # PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
 # --------------------------------------
 # Check the members of `struct sockaddr_storage'.  We need to know about
 # ss_family and ss_len.  (Some platforms follow RFC 2553 and call them
-# __ss_family and __ss_len.)  We also check struct sockaddr's sa_len;
-# if we have to define our own `struct sockaddr_storage', this tells us
-# whether we need to provide an ss_len field.
+# __ss_family and __ss_len.)  We also check struct sockaddr's sa_len.
 AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS],
 [AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family,
 		   struct sockaddr_storage.__ss_family,
diff --git a/configure b/configure
index c6300a9a54..7c10905dfd 100755
--- a/configure
+++ b/configure
@@ -15058,19 +15058,6 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
-fi
-
-ac_fn_c_check_type "$LINENO" "struct sockaddr_storage" "ac_cv_type_struct_sockaddr_storage" "#include <sys/types.h>
-#include <sys/socket.h>
-
-"
-if test "x$ac_cv_type_struct_sockaddr_storage" = xyes; then :
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_STRUCT_SOCKADDR_STORAGE 1
-_ACEOF
-
-
 fi
 
 ac_fn_c_check_member "$LINENO" "struct sockaddr_storage" "ss_family" "ac_cv_member_struct_sockaddr_storage_ss_family" "#include <sys/types.h>
diff --git a/configure.ac b/configure.ac
index 010c8e6a25..d3e402dfc0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1618,7 +1618,6 @@ PGAC_C_COMPUTED_GOTO
 PGAC_STRUCT_TIMEZONE
 PGAC_UNION_SEMUN
 AC_CHECK_TYPES(socklen_t, [], [], [#include <sys/socket.h>])
-PGAC_STRUCT_SOCKADDR_STORAGE
 PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
 PGAC_STRUCT_ADDRINFO
 
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index 3bcc06b2d6..7e2f1495f3 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -21,8 +21,6 @@
 #include <netdb.h>
 #include <netinet/in.h>
 
-#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
-
 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
 #define ss_family __ss_family
@@ -35,27 +33,6 @@
 #define ss_len __ss_len
 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
 #endif
-#else							/* !HAVE_STRUCT_SOCKADDR_STORAGE */
-
-/* Define a struct sockaddr_storage if we don't have one. */
-
-struct sockaddr_storage
-{
-	union
-	{
-		struct sockaddr sa;		/* get the system-dependent fields */
-		int64		ss_align;	/* ensures struct is properly aligned */
-		char		ss_pad[128];	/* ensures struct has desired size */
-	}			ss_stuff;
-};
-
-#define ss_family	ss_stuff.sa.sa_family
-/* It should have an ss_len field if sockaddr has sa_len. */
-#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
-#define ss_len		ss_stuff.sa.sa_len
-#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
-#endif
-#endif							/* HAVE_STRUCT_SOCKADDR_STORAGE */
 
 typedef struct
 {
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 45faf05121..31674bde4e 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -463,9 +463,6 @@
 /* Define to 1 if `sa_len' is a member of `struct sockaddr'. */
 #undef HAVE_STRUCT_SOCKADDR_SA_LEN
 
-/* Define to 1 if the system has the type `struct sockaddr_storage'. */
-#undef HAVE_STRUCT_SOCKADDR_STORAGE
-
 /* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */
 #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
 
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index df594b2fe7..1632931840 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -350,7 +350,6 @@ sub GenerateFiles
 		HAVE_STRUCT_CMSGCRED                     => undef,
 		HAVE_STRUCT_OPTION                       => undef,
 		HAVE_STRUCT_SOCKADDR_SA_LEN              => undef,
-		HAVE_STRUCT_SOCKADDR_STORAGE             => 1,
 		HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY   => 1,
 		HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN      => undef,
 		HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY => undef,
-- 
2.30.2

From d11c344a0cc59d6e657073d243358be16347907c Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.mu...@gmail.com>
Date: Sat, 13 Aug 2022 21:35:18 +1200
Subject: [PATCH 3/3] Remove configure probe for getaddrinfo, and replacement
 code.

SUSv3 and modern Windows have getaddrinfo() and related interfaces.
Drop the replacement implementation, and adjust some headers slightly to
make sure that the OS APIs are visible on both OSes using POSIX header
names.
---
 config/c-library.m4                   |  11 -
 configure                             |  42 ---
 configure.ac                          |  11 -
 src/backend/libpq/auth.c              |   1 +
 src/backend/libpq/hba.c               |   1 +
 src/bin/initdb/initdb.c               |   3 +-
 src/include/common/ip.h               |   4 +-
 src/include/getaddrinfo.h             | 162 ----------
 src/include/libpq/libpq-be.h          |   8 -
 src/include/pg_config.h.in            |   6 -
 src/include/port/win32/netdb.h        |   8 +
 src/include/replication/walreceiver.h |   4 +-
 src/interfaces/libpq/fe-connect.c     |   1 +
 src/interfaces/libpq/libpq-int.h      |   3 +-
 src/port/Makefile                     |   4 -
 src/port/getaddrinfo.c                | 439 --------------------------
 src/tools/msvc/Mkvcbuild.pm           |   2 +-
 src/tools/msvc/Solution.pm            |   2 -
 18 files changed, 22 insertions(+), 690 deletions(-)
 delete mode 100644 src/include/getaddrinfo.h
 delete mode 100644 src/port/getaddrinfo.c

diff --git a/config/c-library.m4 b/config/c-library.m4
index 7a79033730..58453c4f76 100644
--- a/config/c-library.m4
+++ b/config/c-library.m4
@@ -89,17 +89,6 @@ AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS],
 ])])# PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
 
 
-# PGAC_STRUCT_ADDRINFO
-# -----------------------
-# If `struct addrinfo' exists, define HAVE_STRUCT_ADDRINFO.
-AC_DEFUN([PGAC_STRUCT_ADDRINFO],
-[AC_CHECK_TYPES([struct addrinfo], [], [],
-[#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-])])# PGAC_STRUCT_ADDRINFO
-
-
 # PGAC_TYPE_LOCALE_T
 # ------------------
 # Check for the locale_t type and find the right header file.  macOS
diff --git a/configure b/configure
index 7c10905dfd..c1daab15d6 100755
--- a/configure
+++ b/configure
@@ -15119,20 +15119,6 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
-fi
-
-ac_fn_c_check_type "$LINENO" "struct addrinfo" "ac_cv_type_struct_addrinfo" "#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
-"
-if test "x$ac_cv_type_struct_addrinfo" = xyes; then :
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_STRUCT_ADDRINFO 1
-_ACEOF
-
-
 fi
 
 
@@ -16565,34 +16551,6 @@ esac
 $as_echo "$as_me: On $host_os we will use our strtof wrapper." >&6;}
 fi
 
-# System's version of getaddrinfo(), if any, may be used only if we found
-# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h.
-# We use only our own getaddrinfo.c on Windows, but it's time to revisit that.
-if test x"$ac_cv_type_struct_addrinfo" = xyes && \
-   test "$PORTNAME" != "win32"; then
-  ac_fn_c_check_func "$LINENO" "getaddrinfo" "ac_cv_func_getaddrinfo"
-if test "x$ac_cv_func_getaddrinfo" = xyes; then :
-  $as_echo "#define HAVE_GETADDRINFO 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" getaddrinfo.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext"
- ;;
-esac
-
-fi
-
-
-else
-  case " $LIBOBJS " in
-  *" getaddrinfo.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext"
- ;;
-esac
-
-fi
-
 # Similarly, use system's getopt_long() only if system provides struct option.
 if test x"$ac_cv_type_struct_option" = xyes ; then
   ac_fn_c_check_func "$LINENO" "getopt_long" "ac_cv_func_getopt_long"
diff --git a/configure.ac b/configure.ac
index d3e402dfc0..1ce9766a31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1619,7 +1619,6 @@ PGAC_STRUCT_TIMEZONE
 PGAC_UNION_SEMUN
 AC_CHECK_TYPES(socklen_t, [], [], [#include <sys/socket.h>])
 PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
-PGAC_STRUCT_ADDRINFO
 
 PGAC_TYPE_LOCALE_T
 
@@ -1860,16 +1859,6 @@ if test "$PORTNAME" = "win32" -o "$PORTNAME" = "cygwin"; then
 	AC_MSG_NOTICE([On $host_os we will use our strtof wrapper.])
 fi
 
-# System's version of getaddrinfo(), if any, may be used only if we found
-# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h.
-# We use only our own getaddrinfo.c on Windows, but it's time to revisit that.
-if test x"$ac_cv_type_struct_addrinfo" = xyes && \
-   test "$PORTNAME" != "win32"; then
-  AC_REPLACE_FUNCS([getaddrinfo])
-else
-  AC_LIBOBJ(getaddrinfo)
-fi
-
 # Similarly, use system's getopt_long() only if system provides struct option.
 if test x"$ac_cv_type_struct_option" = xyes ; then
   AC_REPLACE_FUNCS([getopt_long])
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 41d60e06d0..290eb17325 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -19,6 +19,7 @@
 #include <sys/select.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <netdb.h>
 #include <pwd.h>
 #include <unistd.h>
 
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index 66f2156cde..857b9e5eb2 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -21,6 +21,7 @@
 #include <fcntl.h>
 #include <sys/param.h>
 #include <sys/socket.h>
+#include <netdb.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <unistd.h>
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 4feb5db3fa..6f56d3f703 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -50,7 +50,9 @@
 
 #include <dirent.h>
 #include <fcntl.h>
+#include <netdb.h>
 #include <sys/stat.h>
+#include <sys/socket.h>
 #include <unistd.h>
 #include <signal.h>
 #include <time.h>
@@ -72,7 +74,6 @@
 #include "common/string.h"
 #include "common/username.h"
 #include "fe_utils/string_utils.h"
-#include "getaddrinfo.h"
 #include "getopt_long.h"
 #include "mb/pg_wchar.h"
 #include "miscadmin.h"
diff --git a/src/include/common/ip.h b/src/include/common/ip.h
index 8414520989..6c044f7fa2 100644
--- a/src/include/common/ip.h
+++ b/src/include/common/ip.h
@@ -14,7 +14,9 @@
 #ifndef IP_H
 #define IP_H
 
-#include "getaddrinfo.h"		/* pgrminclude ignore */
+#include <netdb.h>
+#include <sys/socket.h>
+
 #include "libpq/pqcomm.h"		/* pgrminclude ignore */
 
 
diff --git a/src/include/getaddrinfo.h b/src/include/getaddrinfo.h
deleted file mode 100644
index 2042c2d303..0000000000
--- a/src/include/getaddrinfo.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * getaddrinfo.h
- *	  Support getaddrinfo() on platforms that don't have it.
- *
- * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO,
- * whether or not the library routine getaddrinfo() can be found.  This
- * policy is needed because on some platforms a manually installed libbind.a
- * may provide getaddrinfo(), yet the system headers may not provide the
- * struct definitions needed to call it.  To avoid conflict with the libbind
- * definition in such cases, we rename our routines to pg_xxx() via macros.
- *
- * This code will also work on platforms where struct addrinfo is defined
- * in the system headers but no getaddrinfo() can be located.
- *
- * Copyright (c) 2003-2022, PostgreSQL Global Development Group
- *
- * src/include/getaddrinfo.h
- *
- *-------------------------------------------------------------------------
- */
-#ifndef GETADDRINFO_H
-#define GETADDRINFO_H
-
-#include <sys/socket.h>
-#include <netdb.h>
-
-
-/* Various macros that ought to be in <netdb.h>, but might not be */
-
-#ifndef EAI_FAIL
-#ifndef WIN32
-#define EAI_BADFLAGS	(-1)
-#define EAI_NONAME		(-2)
-#define EAI_AGAIN		(-3)
-#define EAI_FAIL		(-4)
-#define EAI_FAMILY		(-6)
-#define EAI_SOCKTYPE	(-7)
-#define EAI_SERVICE		(-8)
-#define EAI_MEMORY		(-10)
-#define EAI_SYSTEM		(-11)
-#else							/* WIN32 */
-#ifdef _MSC_VER
-#ifndef WSA_NOT_ENOUGH_MEMORY
-#define WSA_NOT_ENOUGH_MEMORY	(WSAENOBUFS)
-#endif
-#define WSATYPE_NOT_FOUND		(WSABASEERR+109)
-#endif
-#define EAI_AGAIN		WSATRY_AGAIN
-#define EAI_BADFLAGS	WSAEINVAL
-#define EAI_FAIL		WSANO_RECOVERY
-#define EAI_FAMILY		WSAEAFNOSUPPORT
-#define EAI_MEMORY		WSA_NOT_ENOUGH_MEMORY
-#define EAI_NODATA		WSANO_DATA
-#define EAI_NONAME		WSAHOST_NOT_FOUND
-#define EAI_SERVICE		WSATYPE_NOT_FOUND
-#define EAI_SOCKTYPE	WSAESOCKTNOSUPPORT
-#endif							/* !WIN32 */
-#endif							/* !EAI_FAIL */
-
-#ifndef AI_PASSIVE
-#define AI_PASSIVE		0x0001
-#endif
-
-#ifndef AI_NUMERICHOST
-/*
- * some platforms don't support AI_NUMERICHOST; define as zero if using
- * the system version of getaddrinfo...
- */
-#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
-#define AI_NUMERICHOST	0
-#else
-#define AI_NUMERICHOST	0x0004
-#endif
-#endif
-
-#ifndef NI_NUMERICHOST
-#define NI_NUMERICHOST	1
-#endif
-#ifndef NI_NUMERICSERV
-#define NI_NUMERICSERV	2
-#endif
-#ifndef NI_NAMEREQD
-#define NI_NAMEREQD		4
-#endif
-
-#ifndef NI_MAXHOST
-#define NI_MAXHOST	1025
-#endif
-#ifndef NI_MAXSERV
-#define NI_MAXSERV	32
-#endif
-
-
-#ifndef HAVE_STRUCT_ADDRINFO
-
-#ifndef WIN32
-struct addrinfo
-{
-	int			ai_flags;
-	int			ai_family;
-	int			ai_socktype;
-	int			ai_protocol;
-	size_t		ai_addrlen;
-	struct sockaddr *ai_addr;
-	char	   *ai_canonname;
-	struct addrinfo *ai_next;
-};
-#else
-/*
- *	The order of the structure elements on Win32 doesn't match the
- *	order specified in the standard, but we have to match it for
- *	IPv6 to work.
- */
-struct addrinfo
-{
-	int			ai_flags;
-	int			ai_family;
-	int			ai_socktype;
-	int			ai_protocol;
-	size_t		ai_addrlen;
-	char	   *ai_canonname;
-	struct sockaddr *ai_addr;
-	struct addrinfo *ai_next;
-};
-#endif
-#endif							/* HAVE_STRUCT_ADDRINFO */
-
-
-#ifndef HAVE_GETADDRINFO
-
-/* Rename private copies per comments above */
-#ifdef getaddrinfo
-#undef getaddrinfo
-#endif
-#define getaddrinfo pg_getaddrinfo
-
-#ifdef freeaddrinfo
-#undef freeaddrinfo
-#endif
-#define freeaddrinfo pg_freeaddrinfo
-
-#ifdef gai_strerror
-#undef gai_strerror
-#endif
-#define gai_strerror pg_gai_strerror
-
-#ifdef getnameinfo
-#undef getnameinfo
-#endif
-#define getnameinfo pg_getnameinfo
-
-extern int	getaddrinfo(const char *node, const char *service,
-						const struct addrinfo *hints, struct addrinfo **res);
-extern void freeaddrinfo(struct addrinfo *res);
-extern const char *gai_strerror(int errcode);
-extern int	getnameinfo(const struct sockaddr *sa, int salen,
-						char *node, int nodelen,
-						char *service, int servicelen, int flags);
-#endif							/* HAVE_GETADDRINFO */
-
-#endif							/* GETADDRINFO_H */
diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h
index 90c20da22b..fa2fd03009 100644
--- a/src/include/libpq/libpq-be.h
+++ b/src/include/libpq/libpq-be.h
@@ -33,14 +33,6 @@
 #else
 #include <gssapi/gssapi.h>
 #endif							/* HAVE_GSSAPI_H */
-/*
- * GSSAPI brings in headers that set a lot of things in the global namespace on win32,
- * that doesn't match the msvc build. It gives a bunch of compiler warnings that we ignore,
- * but also defines a symbol that simply does not exist. Undefine it again.
- */
-#ifdef _MSC_VER
-#undef HAVE_GETADDRINFO
-#endif
 #endif							/* ENABLE_GSS */
 
 #ifdef ENABLE_SSPI
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 31674bde4e..e5e68fac03 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -178,9 +178,6 @@
    */
 #undef HAVE_GCC__SYNC_INT64_CAS
 
-/* Define to 1 if you have the `getaddrinfo' function. */
-#undef HAVE_GETADDRINFO
-
 /* Define to 1 if you have the `gethostbyname_r' function. */
 #undef HAVE_GETHOSTBYNAME_R
 
@@ -451,9 +448,6 @@
 /* Define to 1 if you have the `strsignal' function. */
 #undef HAVE_STRSIGNAL
 
-/* Define to 1 if the system has the type `struct addrinfo'. */
-#undef HAVE_STRUCT_ADDRINFO
-
 /* Define to 1 if the system has the type `struct cmsgcred'. */
 #undef HAVE_STRUCT_CMSGCRED
 
diff --git a/src/include/port/win32/netdb.h b/src/include/port/win32/netdb.h
index ad0627e986..f0cc2c2367 100644
--- a/src/include/port/win32/netdb.h
+++ b/src/include/port/win32/netdb.h
@@ -1 +1,9 @@
 /* src/include/port/win32/netdb.h */
+#ifndef WIN32_NETDB_H
+#define WIN32_NETDB_H
+
+#include <ws2tcpip.h>
+
+#define gai_strerror gai_strerrorA
+
+#endif
diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h
index bd8398de0b..9339f29303 100644
--- a/src/include/replication/walreceiver.h
+++ b/src/include/replication/walreceiver.h
@@ -12,9 +12,11 @@
 #ifndef _WALRECEIVER_H
 #define _WALRECEIVER_H
 
+#include <netdb.h>
+#include <sys/socket.h>
+
 #include "access/xlog.h"
 #include "access/xlogdefs.h"
-#include "getaddrinfo.h"		/* for NI_MAXHOST */
 #include "pgtime.h"
 #include "port/atomics.h"
 #include "replication/logicalproto.h"
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 730e79a31d..0b8fabc7e8 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -18,6 +18,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <ctype.h>
+#include <netdb.h>
 #include <time.h>
 #include <unistd.h>
 
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 51ab51f9f9..1eb752a82d 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -23,6 +23,8 @@
 /* We assume libpq-fe.h has already been included. */
 #include "libpq-events.h"
 
+#include <netdb.h>
+#include <sys/socket.h>
 #include <time.h>
 #ifndef WIN32
 #include <sys/time.h>
@@ -38,7 +40,6 @@
 #endif
 
 /* include stuff common to fe and be */
-#include "getaddrinfo.h"
 #include "libpq/pqcomm.h"
 /* include stuff found in fe only */
 #include "fe-auth-sasl.h"
diff --git a/src/port/Makefile b/src/port/Makefile
index bfe1feb0d4..b3754d8940 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -84,10 +84,6 @@ libpgport.a: $(OBJS)
 	rm -f $@
 	$(AR) $(AROPT) $@ $^
 
-# getaddrinfo.o and getaddrinfo_shlib.o need PTHREAD_CFLAGS (but getaddrinfo_srv.o does not)
-getaddrinfo.o: CFLAGS+=$(PTHREAD_CFLAGS)
-getaddrinfo_shlib.o: CFLAGS+=$(PTHREAD_CFLAGS)
-
 # thread.o and thread_shlib.o need PTHREAD_CFLAGS (but thread_srv.o does not)
 thread.o: CFLAGS+=$(PTHREAD_CFLAGS)
 thread_shlib.o: CFLAGS+=$(PTHREAD_CFLAGS)
diff --git a/src/port/getaddrinfo.c b/src/port/getaddrinfo.c
deleted file mode 100644
index bea7b520f0..0000000000
--- a/src/port/getaddrinfo.c
+++ /dev/null
@@ -1,439 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * getaddrinfo.c
- *	  Support getaddrinfo() on platforms that don't have it.
- *
- * We also supply getnameinfo() here, assuming that the platform will have
- * it if and only if it has getaddrinfo().  If this proves false on some
- * 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 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-2022, PostgreSQL Global Development Group
- *
- * IDENTIFICATION
- *	  src/port/getaddrinfo.c
- *
- *-------------------------------------------------------------------------
- */
-
-/* This is intended to be used in both frontend and backend, so use c.h */
-#include "c.h"
-
-#include <sys/socket.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "getaddrinfo.h"
-#include "libpq/pqcomm.h"		/* needed for struct sockaddr_storage */
-#include "port/pg_bswap.h"
-
-
-#ifdef FRONTEND
-static int	pqGethostbyname(const char *name,
-							struct hostent *resultbuf,
-							char *buffer, size_t buflen,
-							struct hostent **result,
-							int *herrno);
-#endif
-
-#ifdef WIN32
-/*
- * 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.
- * Here we need to declare what the function pointers look like
- */
-typedef int (__stdcall * getaddrinfo_ptr_t) (const char *nodename,
-											 const char *servname,
-											 const struct addrinfo *hints,
-											 struct addrinfo **res);
-
-typedef void (__stdcall * freeaddrinfo_ptr_t) (struct addrinfo *ai);
-
-typedef int (__stdcall * getnameinfo_ptr_t) (const struct sockaddr *sa,
-											 int salen,
-											 char *node, int nodelen,
-											 char *service, int servicelen,
-											 int flags);
-
-/* static pointers to the native routines, so we only do the lookup once. */
-static getaddrinfo_ptr_t getaddrinfo_ptr = NULL;
-static freeaddrinfo_ptr_t freeaddrinfo_ptr = NULL;
-static getnameinfo_ptr_t getnameinfo_ptr = NULL;
-
-
-static bool
-haveNativeWindowsIPv6routines(void)
-{
-	void	   *hLibrary = NULL;
-	static bool alreadyLookedForIpv6routines = false;
-
-	if (alreadyLookedForIpv6routines)
-		return (getaddrinfo_ptr != NULL);
-
-	/*
-	 * For Windows XP and later versions, the IPv6 routines are present in the
-	 * WinSock 2 library (ws2_32.dll).
-	 */
-	hLibrary = LoadLibraryA("ws2_32");
-
-	/* If hLibrary is null, we couldn't find a dll with functions */
-	if (hLibrary != NULL)
-	{
-		/* We found a dll, so now get the addresses of the routines */
-
-		getaddrinfo_ptr = (getaddrinfo_ptr_t) (pg_funcptr_t) GetProcAddress(hLibrary,
-																			"getaddrinfo");
-		freeaddrinfo_ptr = (freeaddrinfo_ptr_t) (pg_funcptr_t) GetProcAddress(hLibrary,
-																			  "freeaddrinfo");
-		getnameinfo_ptr = (getnameinfo_ptr_t) (pg_funcptr_t) GetProcAddress(hLibrary,
-																			"getnameinfo");
-
-		/*
-		 * If any one of the routines is missing, let's play it safe and
-		 * ignore them all
-		 */
-		if (getaddrinfo_ptr == NULL ||
-			freeaddrinfo_ptr == NULL ||
-			getnameinfo_ptr == NULL)
-		{
-			FreeLibrary(hLibrary);
-			hLibrary = NULL;
-			getaddrinfo_ptr = NULL;
-			freeaddrinfo_ptr = NULL;
-			getnameinfo_ptr = NULL;
-		}
-	}
-
-	alreadyLookedForIpv6routines = true;
-	return (getaddrinfo_ptr != NULL);
-}
-#endif
-
-
-/*
- * get address info for ipv4 sockets.
- *
- *	Bugs:	- only one addrinfo is set even though hintp is NULL or
- *		  ai_socktype is 0
- *		- AI_CANONNAME is not supported.
- *		- servname can only be a number, not text.
- */
-int
-getaddrinfo(const char *node, const char *service,
-			const struct addrinfo *hintp,
-			struct addrinfo **res)
-{
-	struct addrinfo *ai;
-	struct sockaddr_in sin,
-			   *psin;
-	struct addrinfo hints;
-
-#ifdef WIN32
-
-	/*
-	 * If Windows has native IPv6 support, use the native Windows routine.
-	 * Otherwise, fall through and use our own code.
-	 */
-	if (haveNativeWindowsIPv6routines())
-		return (*getaddrinfo_ptr) (node, service, hintp, res);
-#endif
-
-	if (hintp == NULL)
-	{
-		memset(&hints, 0, sizeof(hints));
-		hints.ai_family = AF_INET;
-		hints.ai_socktype = SOCK_STREAM;
-	}
-	else
-		memcpy(&hints, hintp, sizeof(hints));
-
-	if (hints.ai_family != AF_INET && hints.ai_family != AF_UNSPEC)
-		return EAI_FAMILY;
-
-	if (hints.ai_socktype == 0)
-		hints.ai_socktype = SOCK_STREAM;
-
-	if (!node && !service)
-		return EAI_NONAME;
-
-	memset(&sin, 0, sizeof(sin));
-
-	sin.sin_family = AF_INET;
-
-	if (node)
-	{
-		if (node[0] == '\0')
-			sin.sin_addr.s_addr = pg_hton32(INADDR_ANY);
-		else if (hints.ai_flags & AI_NUMERICHOST)
-		{
-			if (!inet_aton(node, &sin.sin_addr))
-				return EAI_NONAME;
-		}
-		else
-		{
-			struct hostent *hp;
-
-#ifdef FRONTEND
-			struct hostent hpstr;
-			char		buf[BUFSIZ];
-			int			herrno = 0;
-
-			pqGethostbyname(node, &hpstr, buf, sizeof(buf),
-							&hp, &herrno);
-#else
-			hp = gethostbyname(node);
-#endif
-			if (hp == NULL)
-			{
-				switch (h_errno)
-				{
-					case HOST_NOT_FOUND:
-					case NO_DATA:
-						return EAI_NONAME;
-					case TRY_AGAIN:
-						return EAI_AGAIN;
-					case NO_RECOVERY:
-					default:
-						return EAI_FAIL;
-				}
-			}
-			if (hp->h_addrtype != AF_INET)
-				return EAI_FAIL;
-
-			memcpy(&(sin.sin_addr), hp->h_addr, hp->h_length);
-		}
-	}
-	else
-	{
-		if (hints.ai_flags & AI_PASSIVE)
-			sin.sin_addr.s_addr = pg_hton32(INADDR_ANY);
-		else
-			sin.sin_addr.s_addr = pg_hton32(INADDR_LOOPBACK);
-	}
-
-	if (service)
-		sin.sin_port = pg_hton16((unsigned short) atoi(service));
-
-#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
-	sin.sin_len = sizeof(sin);
-#endif
-
-	ai = malloc(sizeof(*ai));
-	if (!ai)
-		return EAI_MEMORY;
-
-	psin = malloc(sizeof(*psin));
-	if (!psin)
-	{
-		free(ai);
-		return EAI_MEMORY;
-	}
-
-	memcpy(psin, &sin, sizeof(*psin));
-
-	ai->ai_flags = 0;
-	ai->ai_family = AF_INET;
-	ai->ai_socktype = hints.ai_socktype;
-	ai->ai_protocol = hints.ai_protocol;
-	ai->ai_addrlen = sizeof(*psin);
-	ai->ai_addr = (struct sockaddr *) psin;
-	ai->ai_canonname = NULL;
-	ai->ai_next = NULL;
-
-	*res = ai;
-
-	return 0;
-}
-
-
-void
-freeaddrinfo(struct addrinfo *res)
-{
-	if (res)
-	{
-#ifdef WIN32
-
-		/*
-		 * If Windows has native IPv6 support, use the native Windows routine.
-		 * Otherwise, fall through and use our own code.
-		 */
-		if (haveNativeWindowsIPv6routines())
-		{
-			(*freeaddrinfo_ptr) (res);
-			return;
-		}
-#endif
-
-		free(res->ai_addr);
-		free(res);
-	}
-}
-
-
-const char *
-gai_strerror(int errcode)
-{
-#ifdef HAVE_HSTRERROR
-	int			hcode;
-
-	switch (errcode)
-	{
-		case EAI_NONAME:
-			hcode = HOST_NOT_FOUND;
-			break;
-		case EAI_AGAIN:
-			hcode = TRY_AGAIN;
-			break;
-		case EAI_FAIL:
-		default:
-			hcode = NO_RECOVERY;
-			break;
-	}
-
-	return hstrerror(hcode);
-#else							/* !HAVE_HSTRERROR */
-
-	switch (errcode)
-	{
-		case EAI_NONAME:
-			return "Unknown host";
-		case EAI_AGAIN:
-			return "Host name lookup failure";
-			/* Errors below are probably WIN32 only */
-#ifdef EAI_BADFLAGS
-		case EAI_BADFLAGS:
-			return "Invalid argument";
-#endif
-#ifdef EAI_FAMILY
-		case EAI_FAMILY:
-			return "Address family not supported";
-#endif
-#ifdef EAI_MEMORY
-		case EAI_MEMORY:
-			return "Not enough memory";
-#endif
-#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME /* MSVC/WIN64 duplicate */
-		case EAI_NODATA:
-			return "No host data of that type was found";
-#endif
-#ifdef EAI_SERVICE
-		case EAI_SERVICE:
-			return "Class type not found";
-#endif
-#ifdef EAI_SOCKTYPE
-		case EAI_SOCKTYPE:
-			return "Socket type not supported";
-#endif
-		default:
-			return "Unknown server error";
-	}
-#endif							/* HAVE_HSTRERROR */
-}
-
-/*
- * Convert an ipv4 address to a hostname.
- *
- * Bugs:	- Only supports NI_NUMERICHOST and NI_NUMERICSERV behavior.
- *		  It will never resolve a hostname.
- *		- No IPv6 support.
- */
-int
-getnameinfo(const struct sockaddr *sa, int salen,
-			char *node, int nodelen,
-			char *service, int servicelen, int flags)
-{
-#ifdef WIN32
-
-	/*
-	 * If Windows has native IPv6 support, use the native Windows routine.
-	 * Otherwise, fall through and use our own code.
-	 */
-	if (haveNativeWindowsIPv6routines())
-		return (*getnameinfo_ptr) (sa, salen, node, nodelen,
-								   service, servicelen, flags);
-#endif
-
-	/* Invalid arguments. */
-	if (sa == NULL || (node == NULL && service == NULL))
-		return EAI_FAIL;
-
-#ifdef	HAVE_IPV6
-	if (sa->sa_family == AF_INET6)
-		return EAI_FAMILY;
-#endif
-
-	/* Unsupported flags. */
-	if (flags & NI_NAMEREQD)
-		return EAI_AGAIN;
-
-	if (node)
-	{
-		if (sa->sa_family == AF_INET)
-		{
-			if (pg_inet_net_ntop(AF_INET,
-								 &((struct sockaddr_in *) sa)->sin_addr,
-								 sa->sa_family == AF_INET ? 32 : 128,
-								 node, nodelen) == NULL)
-				return EAI_MEMORY;
-		}
-		else
-			return EAI_MEMORY;
-	}
-
-	if (service)
-	{
-		int			ret = -1;
-
-		if (sa->sa_family == AF_INET)
-		{
-			ret = snprintf(service, servicelen, "%d",
-						   pg_ntoh16(((struct sockaddr_in *) sa)->sin_port));
-		}
-		if (ret < 0 || ret >= servicelen)
-			return EAI_MEMORY;
-	}
-
-	return 0;
-}
-
-/*
- * Wrapper around gethostbyname() or gethostbyname_r() to mimic
- * POSIX gethostbyname_r() behaviour, if it is not available or required.
- */
-#ifdef FRONTEND
-static int
-pqGethostbyname(const char *name,
-				struct hostent *resultbuf,
-				char *buffer, size_t buflen,
-				struct hostent **result,
-				int *herrno)
-{
-#if defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETHOSTBYNAME_R)
-
-	/*
-	 * broken (well early POSIX draft) gethostbyname_r() which returns 'struct
-	 * hostent *'
-	 */
-	*result = gethostbyname_r(name, resultbuf, buffer, buflen, herrno);
-	return (*result == NULL) ? -1 : 0;
-#else
-
-	/* no gethostbyname_r(), just use gethostbyname() */
-	*result = gethostbyname(name);
-
-	if (*result != NULL)
-		*herrno = h_errno;
-
-	if (*result != NULL)
-		return 0;
-	else
-		return -1;
-#endif
-}
-#endif							/* FRONTEND */
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 0a4f0d2eaa..85d03372a5 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -101,7 +101,7 @@ sub mkvcbuild
 	our @pgportfiles = qw(
 	  chklocale.c explicit_bzero.c
 	  getpeereid.c inet_aton.c
-	  getaddrinfo.c inet_net_ntop.c kill.c open.c
+	  inet_net_ntop.c kill.c open.c
 	  snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c
 	  dirent.c getopt.c getopt_long.c
 	  preadv.c pwritev.c pg_bitutils.c
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 1632931840..09ad8489a6 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -256,7 +256,6 @@ sub GenerateFiles
 		HAVE_GCC__SYNC_INT32_CAS                    => undef,
 		HAVE_GCC__SYNC_INT32_TAS                    => undef,
 		HAVE_GCC__SYNC_INT64_CAS                    => undef,
-		HAVE_GETADDRINFO                            => undef,
 		HAVE_GETHOSTBYNAME_R                        => undef,
 		HAVE_GETIFADDRS                             => undef,
 		HAVE_GETOPT                                 => undef,
@@ -346,7 +345,6 @@ sub GenerateFiles
 		HAVE_STRLCPY                             => undef,
 		HAVE_STRNLEN                             => 1,
 		HAVE_STRSIGNAL                           => undef,
-		HAVE_STRUCT_ADDRINFO                     => 1,
 		HAVE_STRUCT_CMSGCRED                     => undef,
 		HAVE_STRUCT_OPTION                       => undef,
 		HAVE_STRUCT_SOCKADDR_SA_LEN              => undef,
-- 
2.30.2

Reply via email to