*** a/doc/src/sgml/libpq.sgml
--- b/doc/src/sgml/libpq.sgml
***************
*** 1464,1469 **** char *PQhost(const PGconn *conn);
--- 1464,1487 ----
       </listitem>
      </varlistentry>
  
+     <varlistentry id="libpq-pqhostaddr">
+      <term>
+       <function>PQhostaddr</function>
+       <indexterm>
+        <primary>PQhostaddr</primary>
+       </indexterm>
+      </term>
+ 
+      <listitem>
+       <para>
+        Returns the server numeric IP address or host name of the connection.
+ <synopsis>
+ char *PQhostaddr(const PGconn *conn);
+ </synopsis>
+       </para>
+      </listitem>
+     </varlistentry>
+ 
      <varlistentry id="libpq-pqport">
       <term>
        <function>PQport</function>
*** a/src/bin/psql/command.c
--- b/src/bin/psql/command.c
***************
*** 300,306 **** exec_command(const char *cmd,
  	else if (strcmp(cmd, "conninfo") == 0)
  	{
  		char	   *db = PQdb(pset.db);
! 		char	   *host = PQhost(pset.db);
  
  		if (db == NULL)
  			printf(_("You are currently not connected to a database.\n"));
--- 300,306 ----
  	else if (strcmp(cmd, "conninfo") == 0)
  	{
  		char	   *db = PQdb(pset.db);
! 		char	   *host = (PQhostaddr(pset.db) != NULL) ? PQhostaddr(pset.db) : PQhost(pset.db);
  
  		if (db == NULL)
  			printf(_("You are currently not connected to a database.\n"));
*** a/src/interfaces/libpq/exports.txt
--- b/src/interfaces/libpq/exports.txt
***************
*** 165,167 **** lo_lseek64                162
--- 165,168 ----
  lo_tell64                 163
  lo_truncate64             164
  PQconninfo                165
+ PQhostaddr                166
*** a/src/interfaces/libpq/fe-connect.c
--- b/src/interfaces/libpq/fe-connect.c
***************
*** 5188,5194 **** PQhost(const PGconn *conn)
  {
  	if (!conn)
  		return NULL;
! 	return conn->pghost ? conn->pghost : conn->pgunixsocket;
  }
  
  char *
--- 5188,5211 ----
  {
  	if (!conn)
  		return NULL;
! 	if (conn->pghost != NULL && conn->pghost[0] != '\0')
! 		return conn->pghost;
! 	else
! 	{
! #ifdef HAVE_UNIX_SOCKETS
! 		return conn->pgunixsocket;
! #else
! 		return DefaultHost;
! #endif
! 	}
! }
! 
! char *
! PQhostaddr(const PGconn *conn)
! {
! 	if (!conn)
! 		return NULL;
! 	return conn->pghostaddr;
  }
  
  char *
*** a/src/interfaces/libpq/libpq-fe.h
--- b/src/interfaces/libpq/libpq-fe.h
***************
*** 301,306 **** extern char *PQdb(const PGconn *conn);
--- 301,307 ----
  extern char *PQuser(const PGconn *conn);
  extern char *PQpass(const PGconn *conn);
  extern char *PQhost(const PGconn *conn);
+ extern char *PQhostaddr(const PGconn *conn);
  extern char *PQport(const PGconn *conn);
  extern char *PQtty(const PGconn *conn);
  extern char *PQoptions(const PGconn *conn);
