diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 3ab06a1a1b7..33641ade608 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1464,6 +1464,24 @@ char *PQhost(const PGconn *conn); + + + PQhostaddr + + PQhostaddr + + + + + + Returns the server numeric IP address of the connection. + +char *PQhostaddr(const PGconn *conn); + + + + + PQport diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 49f389071a1..f498cdfee76 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -300,7 +300,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "conninfo") == 0) { char *db = PQdb(pset.db); - char *host = PQhost(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")); diff --git a/src/interfaces/libpq/exports.txt b/src/interfaces/libpq/exports.txt index 93da50df311..cbb6e36c119 100644 --- a/src/interfaces/libpq/exports.txt +++ b/src/interfaces/libpq/exports.txt @@ -165,3 +165,4 @@ lo_lseek64 162 lo_tell64 163 lo_truncate64 164 PQconninfo 165 +PQhostaddr 166 diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 92cdd2cbe35..35672a747b1 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -5200,6 +5200,14 @@ PQhost(const PGconn *conn) } } +char * +PQhostaddr(const PGconn *conn) +{ + if (!conn) + return NULL; + return conn->pghostaddr; +} + char * PQport(const PGconn *conn) { diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index 24b2f98acca..856bdff006f 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -301,6 +301,7 @@ extern char *PQdb(const PGconn *conn); 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);