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

Commit19b1c76

Browse files
committed
Use is_cidr in INET/CIDR structure, rather than the generic 'type'.
1 parent726b42a commit19b1c76

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

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

Lines changed: 24 additions & 24 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.58 2006/01/11 08:43:12 neilc Exp $
4+
*$PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.59 2006/01/23 21:45:47 momjian Exp $
55
*
66
*Jon Postel RIP 16 Oct 1998
77
*/
@@ -22,7 +22,7 @@
2222
#include"utils/inet.h"
2323

2424

25-
staticDatumtext_network(text*src,inttype);
25+
staticDatumtext_network(text*src,intis_cidr);
2626
staticint32network_cmp_internal(inet*a1,inet*a2);
2727
staticintbitncmp(void*l,void*r,intn);
2828
staticbooladdressOK(unsignedchar*a,intbits,intfamily);
@@ -38,8 +38,8 @@ static intip_addrsize(inet *inetptr);
3838
#defineip_bits(inetptr) \
3939
(((inet_struct *)VARDATA(inetptr))->bits)
4040

41-
#defineip_type(inetptr) \
42-
(((inet_struct *)VARDATA(inetptr))->type)
41+
#defineip_is_cidr(inetptr) \
42+
(((inet_struct *)VARDATA(inetptr))->is_cidr)
4343

4444
#defineip_addr(inetptr) \
4545
(((inet_struct *)VARDATA(inetptr))->ipaddr)
@@ -66,7 +66,7 @@ ip_addrsize(inet *inetptr)
6666

6767
/* Common input routine */
6868
staticinet*
69-
network_in(char*src,inttype)
69+
network_in(char*src,boolis_cidr)
7070
{
7171
intbits;
7272
inet*dst;
@@ -85,18 +85,18 @@ network_in(char *src, int type)
8585
ip_family(dst)=PGSQL_AF_INET;
8686

8787
bits=inet_net_pton(ip_family(dst),src,ip_addr(dst),
88-
type ?ip_addrsize(dst) :-1);
88+
is_cidr ?ip_addrsize(dst) :-1);
8989
if ((bits<0)|| (bits>ip_maxbits(dst)))
9090
ereport(ERROR,
9191
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
9292
/* translator: first %s is inet or cidr */
9393
errmsg("invalid input syntax for type %s: \"%s\"",
94-
type ?"cidr" :"inet",src)));
94+
is_cidr ?"cidr" :"inet",src)));
9595

9696
/*
9797
* Error check: CIDR values must not have any bits set beyond the masklen.
9898
*/
99-
if (type)
99+
if (is_cidr)
100100
{
101101
if (!addressOK(ip_addr(dst),bits,ip_family(dst)))
102102
ereport(ERROR,
@@ -109,7 +109,7 @@ network_in(char *src, int type)
109109
+ ((char*)ip_addr(dst)- (char*)VARDATA(dst))
110110
+ip_addrsize(dst);
111111
ip_bits(dst)=bits;
112-
ip_type(dst)=type;
112+
ip_is_cidr(dst)=is_cidr;
113113

114114
returndst;
115115
}
@@ -152,7 +152,7 @@ inet_out(PG_FUNCTION_ARGS)
152152
errmsg("could not format inet value: %m")));
153153

154154
/* For CIDR, add /n if not present */
155-
if (ip_type(src)&&strchr(tmp,'/')==NULL)
155+
if (ip_is_cidr(src)&&strchr(tmp,'/')==NULL)
156156
{
157157
len=strlen(tmp);
158158
snprintf(tmp+len,sizeof(tmp)-len,"/%u",ip_bits(src));
@@ -174,7 +174,7 @@ cidr_out(PG_FUNCTION_ARGS)
174174
*inet_recv- converts external binary format to inet
175175
*
176176
* The external representation is (one byte apiece for)
177-
* family, bits,type, address length, address in network byte order.
177+
* family, bits,is_cidr, address length, address in network byte order.
178178
*/
179179
Datum
180180
inet_recv(PG_FUNCTION_ARGS)
@@ -201,8 +201,8 @@ inet_recv(PG_FUNCTION_ARGS)
201201
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
202202
errmsg("invalid bits in external \"inet\" value")));
203203
ip_bits(addr)=bits;
204-
ip_type(addr)=pq_getmsgbyte(buf);
205-
if (ip_type(addr)!=0&&ip_type(addr)!=1)
204+
ip_is_cidr(addr)=pq_getmsgbyte(buf);
205+
if (ip_is_cidr(addr)!=false&&ip_is_cidr(addr)!=true)
206206
ereport(ERROR,
207207
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
208208
errmsg("invalid type in external \"inet\" value")));
@@ -222,7 +222,7 @@ inet_recv(PG_FUNCTION_ARGS)
222222
/*
223223
* Error check: CIDR values must not have any bits set beyond the masklen.
224224
*/
225-
if (ip_type(addr))
225+
if (ip_is_cidr(addr))
226226
{
227227
if (!addressOK(ip_addr(addr),bits,ip_family(addr)))
228228
ereport(ERROR,
@@ -256,7 +256,7 @@ inet_send(PG_FUNCTION_ARGS)
256256
pq_begintypsend(&buf);
257257
pq_sendbyte(&buf,ip_family(addr));
258258
pq_sendbyte(&buf,ip_bits(addr));
259-
pq_sendbyte(&buf,ip_type(addr));
259+
pq_sendbyte(&buf,ip_is_cidr(addr));
260260
nb=ip_addrsize(addr);
261261
if (nb<0)
262262
nb=0;
@@ -276,7 +276,7 @@ cidr_send(PG_FUNCTION_ARGS)
276276

277277

278278
staticDatum
279-
text_network(text*src,inttype)
279+
text_network(text*src,boolis_cidr)
280280
{
281281
intlen=VARSIZE(src)-VARHDRSZ;
282282

@@ -285,7 +285,7 @@ text_network(text *src, int type)
285285
memcpy(str,VARDATA(src),len);
286286
*(str+len)='\0';
287287

288-
PG_RETURN_INET_P(network_in(str,type));
288+
PG_RETURN_INET_P(network_in(str,is_cidr));
289289
}
290290

291291

@@ -425,8 +425,8 @@ network_ne(PG_FUNCTION_ARGS)
425425
/*
426426
* Support function for hash indexes on inet/cidr.
427427
*
428-
* Since network_cmp considers only ip_family, ip_bits, and ip_addr,
429-
*onlythese fields may be used in the hash; in particular don't usetype.
428+
* Since network_cmp considers only ip_family, ip_bits, and ip_addr, only
429+
* these fields may be used in the hash; in particular don't useis_cidr.
430430
*/
431431
Datum
432432
hashinet(PG_FUNCTION_ARGS)
@@ -575,7 +575,7 @@ network_abbrev(PG_FUNCTION_ARGS)
575575
intlen;
576576
chartmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
577577

578-
if (ip_type(ip))
578+
if (ip_is_cidr(ip))
579579
dst=inet_cidr_ntop(ip_family(ip),ip_addr(ip),
580580
ip_bits(ip),tmp,sizeof(tmp));
581581
else
@@ -666,7 +666,7 @@ network_broadcast(PG_FUNCTION_ARGS)
666666

667667
ip_family(dst)=ip_family(ip);
668668
ip_bits(dst)=ip_bits(ip);
669-
ip_type(dst)=0;
669+
ip_is_cidr(dst)=false;
670670
VARATT_SIZEP(dst)=VARHDRSZ
671671
+ ((char*)ip_addr(dst)- (char*)VARDATA(dst))
672672
+ip_addrsize(dst);
@@ -712,7 +712,7 @@ network_network(PG_FUNCTION_ARGS)
712712

713713
ip_family(dst)=ip_family(ip);
714714
ip_bits(dst)=ip_bits(ip);
715-
ip_type(dst)=1;
715+
ip_is_cidr(dst)=true;
716716
VARATT_SIZEP(dst)=VARHDRSZ
717717
+ ((char*)ip_addr(dst)- (char*)VARDATA(dst))
718718
+ip_addrsize(dst);
@@ -756,7 +756,7 @@ network_netmask(PG_FUNCTION_ARGS)
756756

757757
ip_family(dst)=ip_family(ip);
758758
ip_bits(dst)=ip_maxbits(ip);
759-
ip_type(dst)=0;
759+
ip_is_cidr(dst)=false;
760760
VARATT_SIZEP(dst)=VARHDRSZ
761761
+ ((char*)ip_addr(dst)- (char*)VARDATA(dst))
762762
+ip_addrsize(dst);
@@ -806,7 +806,7 @@ network_hostmask(PG_FUNCTION_ARGS)
806806

807807
ip_family(dst)=ip_family(ip);
808808
ip_bits(dst)=ip_maxbits(ip);
809-
ip_type(dst)=0;
809+
ip_is_cidr(dst)=false;
810810
VARATT_SIZEP(dst)=VARHDRSZ
811811
+ ((char*)ip_addr(dst)- (char*)VARDATA(dst))
812812
+ip_addrsize(dst);

‎src/include/utils/inet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/inet.h,v 1.20 2004/12/31 22:03:46 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/inet.h,v 1.21 2006/01/23 21:45:47 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -22,7 +22,7 @@ typedef struct
2222
{
2323
unsignedcharfamily;/* PGSQL_AF_INET or PGSQL_AF_INET6 */
2424
unsignedcharbits;/* number of bits in netmask */
25-
unsignedchartype;/*0 = inet, 1 =cidr */
25+
boolis_cidr;/*iscidr? */
2626
unsignedcharipaddr[16];/* up to 128 bits of address */
2727
}inet_struct;
2828

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp