Magnus Hagander wrote:
> On Fri, Nov 12, 2010 at 15:02, Bruce Momjian <[email protected]> wrote:
> > Tom Lane wrote:
> >> Bruce Momjian <[email protected]> writes:
> >> > I have developed the attached patch to report whether IPv4 or IPv6 are
> >> > being used.
> >>
> >> What's the use of that exactly? ?It doesn't really respond to Peter's
> >> concern, I think.
> >
> > Peter liked:
> >
> >> And I agree it's not very friendly in this specific case - I
> >> wonder if we should log it as "localhost (127.0.0.1) and "localhost
> >> (::1)" (and similar for any other case that returns more than one
> >> address).
> >
> > What this will show is:
> >
> > ? ? ? ?localhost (IPv4)
> > ? ? ? ?localhost (IPv6)
> >
> > Is that good? ?I can't figure out how to do ::1 because when you supply
> > a host _name_, there is no reverse mapping done. ?Looking at the code,
> > we test for a host name, then a host ip, and don't assume they are both
> > set.
>
> The address is in conn->raddr, no? When you've put in a host name, we
> do a forward lookup, so conn->raddr should contain ::1 already? You
> only need the reverse mapping to get the "localhost" part, if I read
> the code correctly?
OK, I found out how to get the IP address with the attached patch. The
problem is that only pghost is set, never pghostaddr. I am not even
sure how that would get set for this code because my tests show it is
not:
$ psql -h localhost test
pghost = localhost
--> pghostaddr = (null)
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and
accepting
TCP/IP connections on port 5432?
$ psql -h 127.0.0.1 test
pghost = 127.0.0.1
pghostaddr = (null)
psql: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
To get this to work, I compared pghost with the raddr value, and printed
the IP address if it was not already printed. There is still a problem
about threading that I can fix.
Is this what we want?
--
Bruce Momjian <[email protected]> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 8f318a1..f3307f3 100644
*** a/src/interfaces/libpq/fe-connect.c
--- b/src/interfaces/libpq/fe-connect.c
*************** connectFailureMessage(PGconn *conn, int
*** 960,968 ****
else
#endif /* HAVE_UNIX_SOCKETS */
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not connect to server: %s\n"
! "\tIs the server running on host \"%s\" and accepting\n"
"\tTCP/IP connections on port %s?\n"),
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
conn->pghostaddr
--- 960,976 ----
else
#endif /* HAVE_UNIX_SOCKETS */
{
+ struct sockaddr_in *remote_addr = (struct sockaddr_in *) &conn->raddr.addr;
+ /* not thread safe */
+ char *remote_ip = inet_ntoa(remote_addr->sin_addr);
+ bool host_ip_match = strcmp(conn->pghost, remote_ip) == 0;
+
+ fprintf(stderr, "pghost = %s\n", conn->pghost);
+ fprintf(stderr, "pghostaddr = %s\n", conn->pghostaddr);
+
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not connect to server: %s\n"
! "\tIs the server running on host \"%s\" %s%s%sand accepting\n"
"\tTCP/IP connections on port %s?\n"),
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
conn->pghostaddr
*************** connectFailureMessage(PGconn *conn, int
*** 970,975 ****
--- 978,987 ----
: (conn->pghost
? conn->pghost
: "???"),
+ /* display the IP address only if not already output */
+ !host_ip_match ? "(" : "",
+ !host_ip_match ? remote_ip : "",
+ !host_ip_match ? ") " : "",
conn->pgport);
}
}
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers