1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-22 23:02:54 +03:00

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.
This commit is contained in:
Fujii Masao 2014-01-24 02:32:39 +09:00
parent d5bc6ce6ac
commit 9f80f4835a
5 changed files with 29 additions and 1 deletions

View File

@ -1464,6 +1464,24 @@ char *PQhost(const PGconn *conn);
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry id="libpq-pqhostaddr">
<term>
<function>PQhostaddr</function>
<indexterm>
<primary>PQhostaddr</primary>
</indexterm>
</term>
<listitem>
<para>
Returns the server numeric IP address of the connection.
<synopsis>
char *PQhostaddr(const PGconn *conn);
</synopsis>
</para>
</listitem>
</varlistentry>
<varlistentry id="libpq-pqport"> <varlistentry id="libpq-pqport">
<term> <term>
<function>PQport</function> <function>PQport</function>

View File

@ -300,7 +300,7 @@ exec_command(const char *cmd,
else if (strcmp(cmd, "conninfo") == 0) else if (strcmp(cmd, "conninfo") == 0)
{ {
char *db = PQdb(pset.db); 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) if (db == NULL)
printf(_("You are currently not connected to a database.\n")); printf(_("You are currently not connected to a database.\n"));

View File

@ -165,3 +165,4 @@ lo_lseek64 162
lo_tell64 163 lo_tell64 163
lo_truncate64 164 lo_truncate64 164
PQconninfo 165 PQconninfo 165
PQhostaddr 166

View File

@ -5200,6 +5200,14 @@ PQhost(const PGconn *conn)
} }
} }
char *
PQhostaddr(const PGconn *conn)
{
if (!conn)
return NULL;
return conn->pghostaddr;
}
char * char *
PQport(const PGconn *conn) PQport(const PGconn *conn)
{ {

View File

@ -301,6 +301,7 @@ extern char *PQdb(const PGconn *conn);
extern char *PQuser(const PGconn *conn); extern char *PQuser(const PGconn *conn);
extern char *PQpass(const PGconn *conn); extern char *PQpass(const PGconn *conn);
extern char *PQhost(const PGconn *conn); extern char *PQhost(const PGconn *conn);
extern char *PQhostaddr(const PGconn *conn);
extern char *PQport(const PGconn *conn); extern char *PQport(const PGconn *conn);
extern char *PQtty(const PGconn *conn); extern char *PQtty(const PGconn *conn);
extern char *PQoptions(const PGconn *conn); extern char *PQoptions(const PGconn *conn);