Index: src/backend/utils/adt/network.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/network.c,v retrieving revision 1.49 diff -u -r1.49 network.c --- src/backend/utils/adt/network.c 1 Dec 2003 18:50:19 -0000 1.49 +++ src/backend/utils/adt/network.c 14 May 2004 22:04:22 -0000 @@ -14,7 +14,9 @@ #include #include "catalog/pg_type.h" +#include "libpq/libpq-be.h" #include "libpq/pqformat.h" +#include "miscadmin.h" #include "utils/builtins.h" #include "utils/inet.h" @@ -128,6 +130,26 @@ char *src = PG_GETARG_CSTRING(0); PG_RETURN_INET_P(network_in(src, 1)); +} + +/* INET that the client is connecting from */ +Datum +inet_client_addr(PG_FUNCTION_ARGS) +{ + if (MyProcPort == NULL) + PG_RETURN_NULL(); + + switch (MyProcPort->raddr.addr.ss_family) { + case AF_INET: +#ifdef HAVE_IPV6 + case AF_INET6: +#endif + break; + default: + PG_RETURN_NULL(); + } + + PG_RETURN_INET_P(network_in(MyProcPort->remote_host, 0)); } /* Index: doc/src/sgml/func.sgml =================================================================== RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/func.sgml,v retrieving revision 1.201 diff -u -r1.201 func.sgml --- doc/src/sgml/func.sgml 10 May 2004 22:44:42 -0000 1.201 +++ doc/src/sgml/func.sgml 14 May 2004 22:04:23 -0000 @@ -6583,6 +6583,12 @@ + inet_client_addr + inet + address of the remote connection + + + session_user name session user name @@ -6636,6 +6642,14 @@ they must be called without trailing parentheses. + + + inet_client_addr returns the IPv4 or IPv6 + (if configured) address of the host connecting to the database. + If the connection is local and not a network connection, + inet_client_addr returns + NULL. + current_schema returns the name of the schema that is Index: src/include/catalog/pg_proc.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.328 diff -u -r1.328 pg_proc.h --- src/include/catalog/pg_proc.h 7 May 2004 16:57:16 -0000 1.328 +++ src/include/catalog/pg_proc.h 14 May 2004 22:04:25 -0000 @@ -2343,6 +2343,8 @@ DESCR("I/O"); DATA(insert OID = 911 ( inet_out PGNSP PGUID 12 f f t f i 1 2275 "869" _null_ inet_out - _null_ )); DESCR("I/O"); +DATA(insert OID = 912 ( inet_client_addr PGNSP PGUID 12 f f f f s 0 869 "" _null_ inet_client_addr - _null_ )); +DESCR("Returns the INET address of the client connected to the backend"); /* for cidr type support */ DATA(insert OID = 1267 ( cidr_in PGNSP PGUID 12 f f t f i 1 650 "2275" _null_ cidr_in - _null_ )); Index: src/include/utils/builtins.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/utils/builtins.h,v retrieving revision 1.237 diff -u -r1.237 builtins.h --- src/include/utils/builtins.h 5 May 2004 04:48:47 -0000 1.237 +++ src/include/utils/builtins.h 14 May 2004 22:04:25 -0000 @@ -645,6 +645,7 @@ void *dst, size_t size); /* network.c */ +extern Datum inet_client_addr(PG_FUNCTION_ARGS); extern Datum inet_in(PG_FUNCTION_ARGS); extern Datum inet_out(PG_FUNCTION_ARGS); extern Datum inet_recv(PG_FUNCTION_ARGS);