diff options
| author | Fujii Masao <fujii@postgresql.org> | 2014-01-24 02:32:39 +0900 |
|---|---|---|
| committer | Fujii Masao <fujii@postgresql.org> | 2014-01-24 02:32:39 +0900 |
| commit | 9f80f4835a55a1cbffcda5d23a617917f3286c14 (patch) | |
| tree | 085b264cb9300b27bb8f5866e1eaff6fc7420018 /src | |
| parent | d5bc6ce6ac20e6de8b61946977db14e13acec2a0 (diff) | |
| download | postgresql-9f80f4835a55a1cbffcda5d23a617917f3286c14.tar.gz | |
Add libpq function PQhostaddr().
There was a bug in the psql's meta command \conninfo. When the
IP address was specified in the hostaddr and psql used it to create
a connection (i.e., psql -d "hostaddr=xxx"), \conninfo could not
display that address. This is because \conninfo got the connection
information only from PQhost() which could not return hostaddr.
This patch adds PQhostaddr(), and changes \conninfo so that it
can display not only the host name that PQhost() returns but also
the IP address which PQhostaddr() returns.
The bug has existed since 9.1 where \conninfo was introduced.
But it's too late to add new libpq function into the released versions,
so no backpatch.
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/psql/command.c | 2 | ||||
| -rw-r--r-- | src/interfaces/libpq/exports.txt | 1 | ||||
| -rw-r--r-- | src/interfaces/libpq/fe-connect.c | 8 | ||||
| -rw-r--r-- | src/interfaces/libpq/libpq-fe.h | 1 |
4 files changed, 11 insertions, 1 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 49f389071a..f498cdfee7 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 93da50df31..cbb6e36c11 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 92cdd2cbe3..35672a747b 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -5201,6 +5201,14 @@ PQhost(const PGconn *conn) } char * +PQhostaddr(const PGconn *conn) +{ + if (!conn) + return NULL; + return conn->pghostaddr; +} + +char * PQport(const PGconn *conn) { if (!conn) diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index 24b2f98acc..856bdff006 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); |
