Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f80f48

Browse files
committed
Add libpq function PQhostaddr().
There was a bug in the psql's meta command \conninfo. When theIP address was specified in the hostaddr and psql used it to createa connection (i.e., psql -d "hostaddr=xxx"), \conninfo could notdisplay that address. This is because \conninfo got the connectioninformation only from PQhost() which could not return hostaddr.This patch adds PQhostaddr(), and changes \conninfo so that itcan display not only the host name that PQhost() returns but alsothe 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.
1 parentd5bc6ce commit9f80f48

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,24 @@ char *PQhost(const PGconn *conn);
14641464
</listitem>
14651465
</varlistentry>
14661466

1467+
<varlistentry id="libpq-pqhostaddr">
1468+
<term>
1469+
<function>PQhostaddr</function>
1470+
<indexterm>
1471+
<primary>PQhostaddr</primary>
1472+
</indexterm>
1473+
</term>
1474+
1475+
<listitem>
1476+
<para>
1477+
Returns the server numeric IP address of the connection.
1478+
<synopsis>
1479+
char *PQhostaddr(const PGconn *conn);
1480+
</synopsis>
1481+
</para>
1482+
</listitem>
1483+
</varlistentry>
1484+
14671485
<varlistentry id="libpq-pqport">
14681486
<term>
14691487
<function>PQport</function>

‎src/bin/psql/command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ exec_command(const char *cmd,
300300
elseif (strcmp(cmd,"conninfo")==0)
301301
{
302302
char*db=PQdb(pset.db);
303-
char*host=PQhost(pset.db);
303+
char*host=(PQhostaddr(pset.db)!=NULL) ?PQhostaddr(pset.db) :PQhost(pset.db);
304304

305305
if (db==NULL)
306306
printf(_("You are currently not connected to a database.\n"));

‎src/interfaces/libpq/exports.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,4 @@ lo_lseek64 162
165165
lo_tell64 163
166166
lo_truncate64 164
167167
PQconninfo 165
168+
PQhostaddr 166

‎src/interfaces/libpq/fe-connect.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5200,6 +5200,14 @@ PQhost(const PGconn *conn)
52005200
}
52015201
}
52025202

5203+
char*
5204+
PQhostaddr(constPGconn*conn)
5205+
{
5206+
if (!conn)
5207+
returnNULL;
5208+
returnconn->pghostaddr;
5209+
}
5210+
52035211
char*
52045212
PQport(constPGconn*conn)
52055213
{

‎src/interfaces/libpq/libpq-fe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ extern char *PQdb(const PGconn *conn);
301301
externchar*PQuser(constPGconn*conn);
302302
externchar*PQpass(constPGconn*conn);
303303
externchar*PQhost(constPGconn*conn);
304+
externchar*PQhostaddr(constPGconn*conn);
304305
externchar*PQport(constPGconn*conn);
305306
externchar*PQtty(constPGconn*conn);
306307
externchar*PQoptions(constPGconn*conn);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp