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

Commitba0f9ff

Browse files
committed
Code review for recently-added network functions. Get it to work when
log_hostname is enabled, clean up documentation.
1 parent88961fc commitba0f9ff

File tree

4 files changed

+192
-135
lines changed

4 files changed

+192
-135
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.206 2004/06/02 21:34:49momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.207 2004/06/13 19:56:49tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -6609,25 +6609,25 @@ SELECT NULLIF(value, '(none)') ...
66096609
</row>
66106610

66116611
<row>
6612-
<entry><function>inet_client_addr</function></entry>
6612+
<entry><function>inet_client_addr()</function></entry>
66136613
<entry><type>inet</type></entry>
66146614
<entry>address of the remote connection</entry>
66156615
</row>
66166616

66176617
<row>
6618-
<entry><function>inet_client_port</function></entry>
6618+
<entry><function>inet_client_port()</function></entry>
66196619
<entry><type>int4</type></entry>
66206620
<entry>port of the remote connection</entry>
66216621
</row>
66226622

66236623
<row>
6624-
<entry><function>inet_server_addr</function></entry>
6624+
<entry><function>inet_server_addr()</function></entry>
66256625
<entry><type>inet</type></entry>
66266626
<entry>address of the local connection</entry>
66276627
</row>
66286628

66296629
<row>
6630-
<entry><function>inet_server_port</function></entry>
6630+
<entry><function>inet_server_port()</function></entry>
66316631
<entry><type>int4</type></entry>
66326632
<entry>port of the local connection</entry>
66336633
</row>
@@ -6687,17 +6687,6 @@ SELECT NULLIF(value, '(none)') ...
66876687
</para>
66886688
</note>
66896689

6690-
<para>
6691-
<function>inet_client_addr</function> and
6692-
<function>inet_server_addr</function> return the IPv4 or IPv6 (if
6693-
configured) address of the remote or local host connecting to the
6694-
database, respectively. <function>inet_client_port</function>
6695-
and <function>inet_server_port</function> return the port number
6696-
of the remote or local host connecting to the database,
6697-
respectively. If the connection is not a network connection,
6698-
these functions will return <literal>NULL</literal>.
6699-
</para>
6700-
67016690
<para>
67026691
<function>current_schema</function> returns the name of the schema that is
67036692
at the front of the search path (or a null value if the search path is
@@ -6718,6 +6707,33 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
67186707
</para>
67196708
</note>
67206709

6710+
<indexterm zone="functions-misc">
6711+
<primary>inet_client_addr</primary>
6712+
</indexterm>
6713+
6714+
<indexterm zone="functions-misc">
6715+
<primary>inet_client_port</primary>
6716+
</indexterm>
6717+
6718+
<indexterm zone="functions-misc">
6719+
<primary>inet_server_addr</primary>
6720+
</indexterm>
6721+
6722+
<indexterm zone="functions-misc">
6723+
<primary>inet_server_port</primary>
6724+
</indexterm>
6725+
6726+
<para>
6727+
<function>inet_client_addr</function> returns the IP address of the
6728+
current client, and <function>inet_client_port</function> returns the
6729+
port number.
6730+
<function>inet_server_addr</function> returns the IP address on which
6731+
the server accepted the current connection, and
6732+
<function>inet_server_port</function> returns the port number.
6733+
All these functions return NULL if the connection is via a Unix-domain
6734+
socket.
6735+
</para>
6736+
67216737
<indexterm zone="functions-misc">
67226738
<primary>version</primary>
67236739
</indexterm>

‎src/backend/utils/adt/network.c

Lines changed: 145 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
*PostgreSQL type definitions for the INET and CIDR types.
33
*
4-
*$PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.50 2004/05/26 18:35:38 momjian Exp $
4+
*$PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.51 2004/06/13 19:56:50 tgl Exp $
55
*
66
*Jon Postel RIP 16 Oct 1998
77
*/
@@ -133,109 +133,6 @@ cidr_in(PG_FUNCTION_ARGS)
133133
PG_RETURN_INET_P(network_in(src,1));
134134
}
135135

136-
/* INET that the client is connecting from */
137-
Datum
138-
inet_client_addr(PG_FUNCTION_ARGS)
139-
{
140-
Port*port=MyProcPort;
141-
142-
if (port==NULL)
143-
PG_RETURN_NULL();
144-
145-
switch (port->raddr.addr.ss_family) {
146-
caseAF_INET:
147-
#ifdefHAVE_IPV6
148-
caseAF_INET6:
149-
#endif
150-
break;
151-
default:
152-
PG_RETURN_NULL();
153-
}
154-
155-
PG_RETURN_INET_P(network_in(port->remote_host,0));
156-
}
157-
158-
159-
/* port that the client is connecting from */
160-
Datum
161-
inet_client_port(PG_FUNCTION_ARGS)
162-
{
163-
Port*port=MyProcPort;
164-
165-
if (port==NULL)
166-
PG_RETURN_NULL();
167-
168-
PG_RETURN_INT32(DirectFunctionCall1(int4in,CStringGetDatum(port->remote_port)));
169-
}
170-
171-
172-
/* server INET that the client connected to */
173-
Datum
174-
inet_server_addr(PG_FUNCTION_ARGS)
175-
{
176-
Port*port=MyProcPort;
177-
charlocal_host[NI_MAXHOST];
178-
intret;
179-
180-
if (port==NULL)
181-
PG_RETURN_NULL();
182-
183-
switch (port->laddr.addr.ss_family) {
184-
caseAF_INET:
185-
#ifdefHAVE_IPV6
186-
caseAF_INET6:
187-
#endif
188-
break;
189-
default:
190-
PG_RETURN_NULL();
191-
}
192-
193-
local_host[0]='\0';
194-
195-
ret=getnameinfo_all(&port->laddr.addr,port->laddr.salen,
196-
local_host,sizeof(local_host),
197-
NULL,0,
198-
NI_NUMERICHOST |NI_NUMERICSERV);
199-
if (ret)
200-
PG_RETURN_NULL();
201-
202-
PG_RETURN_INET_P(network_in(local_host,0));
203-
}
204-
205-
206-
/* port that the server accepted the connection on */
207-
Datum
208-
inet_server_port(PG_FUNCTION_ARGS)
209-
{
210-
Port*port=MyProcPort;
211-
charlocal_port[NI_MAXSERV];
212-
intret;
213-
214-
if (port==NULL)
215-
PG_RETURN_NULL();
216-
217-
switch (port->laddr.addr.ss_family) {
218-
caseAF_INET:
219-
#ifdefHAVE_IPV6
220-
caseAF_INET6:
221-
#endif
222-
break;
223-
default:
224-
PG_RETURN_NULL();
225-
}
226-
227-
local_port[0]='\0';
228-
229-
ret=getnameinfo_all(&port->laddr.addr,port->laddr.salen,
230-
NULL,0,
231-
local_port,sizeof(local_port),
232-
NI_NUMERICHOST |NI_NUMERICSERV);
233-
if (ret)
234-
PG_RETURN_NULL();
235-
236-
PG_RETURN_INT32(DirectFunctionCall1(int4in,CStringGetDatum(local_port)));
237-
}
238-
239136

240137
/*
241138
*INET address output function.
@@ -1069,3 +966,147 @@ network_scan_last(Datum in)
1069966
DirectFunctionCall1(network_broadcast,in),
1070967
Int32GetDatum(-1));
1071968
}
969+
970+
971+
/*
972+
* IP address that the client is connecting from (NULL if Unix socket)
973+
*/
974+
Datum
975+
inet_client_addr(PG_FUNCTION_ARGS)
976+
{
977+
Port*port=MyProcPort;
978+
charremote_host[NI_MAXHOST];
979+
intret;
980+
981+
if (port==NULL)
982+
PG_RETURN_NULL();
983+
984+
switch (port->raddr.addr.ss_family) {
985+
caseAF_INET:
986+
#ifdefHAVE_IPV6
987+
caseAF_INET6:
988+
#endif
989+
break;
990+
default:
991+
PG_RETURN_NULL();
992+
}
993+
994+
remote_host[0]='\0';
995+
996+
ret=getnameinfo_all(&port->raddr.addr,port->raddr.salen,
997+
remote_host,sizeof(remote_host),
998+
NULL,0,
999+
NI_NUMERICHOST |NI_NUMERICSERV);
1000+
if (ret)
1001+
PG_RETURN_NULL();
1002+
1003+
PG_RETURN_INET_P(network_in(remote_host,0));
1004+
}
1005+
1006+
1007+
/*
1008+
* port that the client is connecting from (NULL if Unix socket)
1009+
*/
1010+
Datum
1011+
inet_client_port(PG_FUNCTION_ARGS)
1012+
{
1013+
Port*port=MyProcPort;
1014+
charremote_port[NI_MAXSERV];
1015+
intret;
1016+
1017+
if (port==NULL)
1018+
PG_RETURN_NULL();
1019+
1020+
switch (port->raddr.addr.ss_family) {
1021+
caseAF_INET:
1022+
#ifdefHAVE_IPV6
1023+
caseAF_INET6:
1024+
#endif
1025+
break;
1026+
default:
1027+
PG_RETURN_NULL();
1028+
}
1029+
1030+
remote_port[0]='\0';
1031+
1032+
ret=getnameinfo_all(&port->raddr.addr,port->raddr.salen,
1033+
NULL,0,
1034+
remote_port,sizeof(remote_port),
1035+
NI_NUMERICHOST |NI_NUMERICSERV);
1036+
if (ret)
1037+
PG_RETURN_NULL();
1038+
1039+
PG_RETURN_DATUM(DirectFunctionCall1(int4in,CStringGetDatum(remote_port)));
1040+
}
1041+
1042+
1043+
/*
1044+
* IP address that the server accepted the connection on (NULL if Unix socket)
1045+
*/
1046+
Datum
1047+
inet_server_addr(PG_FUNCTION_ARGS)
1048+
{
1049+
Port*port=MyProcPort;
1050+
charlocal_host[NI_MAXHOST];
1051+
intret;
1052+
1053+
if (port==NULL)
1054+
PG_RETURN_NULL();
1055+
1056+
switch (port->laddr.addr.ss_family) {
1057+
caseAF_INET:
1058+
#ifdefHAVE_IPV6
1059+
caseAF_INET6:
1060+
#endif
1061+
break;
1062+
default:
1063+
PG_RETURN_NULL();
1064+
}
1065+
1066+
local_host[0]='\0';
1067+
1068+
ret=getnameinfo_all(&port->laddr.addr,port->laddr.salen,
1069+
local_host,sizeof(local_host),
1070+
NULL,0,
1071+
NI_NUMERICHOST |NI_NUMERICSERV);
1072+
if (ret)
1073+
PG_RETURN_NULL();
1074+
1075+
PG_RETURN_INET_P(network_in(local_host,0));
1076+
}
1077+
1078+
1079+
/*
1080+
* port that the server accepted the connection on (NULL if Unix socket)
1081+
*/
1082+
Datum
1083+
inet_server_port(PG_FUNCTION_ARGS)
1084+
{
1085+
Port*port=MyProcPort;
1086+
charlocal_port[NI_MAXSERV];
1087+
intret;
1088+
1089+
if (port==NULL)
1090+
PG_RETURN_NULL();
1091+
1092+
switch (port->laddr.addr.ss_family) {
1093+
caseAF_INET:
1094+
#ifdefHAVE_IPV6
1095+
caseAF_INET6:
1096+
#endif
1097+
break;
1098+
default:
1099+
PG_RETURN_NULL();
1100+
}
1101+
1102+
local_port[0]='\0';
1103+
1104+
ret=getnameinfo_all(&port->laddr.addr,port->laddr.salen,
1105+
NULL,0,
1106+
local_port,sizeof(local_port),
1107+
NI_NUMERICHOST |NI_NUMERICSERV);
1108+
if (ret)
1109+
PG_RETURN_NULL();
1110+
1111+
PG_RETURN_DATUM(DirectFunctionCall1(int4in,CStringGetDatum(local_port)));
1112+
}

‎src/include/catalog/pg_proc.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.335 2004/06/06 19:07:00 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.336 2004/06/13 19:56:51 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2346,15 +2346,6 @@ DESCR("I/O");
23462346
DATA(insertOID=911 (inet_outPGNSPPGUID12fftfi12275"869"_null_inet_out-_null_ ));
23472347
DESCR("I/O");
23482348

2349-
DATA(insertOID=2196 (inet_client_addrPGNSPPGUID12ffffs0869""_null_inet_client_addr-_null_ ));
2350-
DESCR("Returns the INET address of the client connected to the backend");
2351-
DATA(insertOID=2197 (inet_client_portPGNSPPGUID12ffffs023""_null_inet_client_port-_null_ ));
2352-
DESCR("Returns the client's port number for this connection");
2353-
DATA(insertOID=2198 (inet_server_addrPGNSPPGUID12ffffs0869""_null_inet_server_addr-_null_ ));
2354-
DESCR("Returns the INET address that the backend is using to service the connection");
2355-
DATA(insertOID=2199 (inet_server_portPGNSPPGUID12ffffs023""_null_inet_server_port-_null_ ));
2356-
DESCR("Returns the servers's port number for this connection");
2357-
23582349
/* for cidr type support */
23592350
DATA(insertOID=1267 (cidr_inPGNSPPGUID12fftfi1650"2275"_null_cidr_in-_null_ ));
23602351
DESCR("I/O");
@@ -2411,6 +2402,15 @@ DESCR("text to cidr");
24112402
DATA(insertOID=1715 (set_masklenPGNSPPGUID12fftfi2869"869 23"_null_inet_set_masklen-_null_ ));
24122403
DESCR("change the netmask of an inet");
24132404

2405+
DATA(insertOID=2196 (inet_client_addrPGNSPPGUID12ffffs0869""_null_inet_client_addr-_null_ ));
2406+
DESCR("INET address of the client");
2407+
DATA(insertOID=2197 (inet_client_portPGNSPPGUID12ffffs023""_null_inet_client_port-_null_ ));
2408+
DESCR("client's port number for this connection");
2409+
DATA(insertOID=2198 (inet_server_addrPGNSPPGUID12ffffs0869""_null_inet_server_addr-_null_ ));
2410+
DESCR("INET address of the server");
2411+
DATA(insertOID=2199 (inet_server_portPGNSPPGUID12ffffs023""_null_inet_server_port-_null_ ));
2412+
DESCR("server's port number for this connection");
2413+
24142414
DATA(insertOID=1686 (numericPGNSPPGUID12fftfi11700"25"_null_text_numeric-_null_ ));
24152415
DESCR("(internal)");
24162416
DATA(insertOID=1688 (textPGNSPPGUID12fftfi125"1700"_null_numeric_text-_null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp