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

Commitc5336a8

Browse files
committed
netmask() and hostmask() functions should return maximum-length masklen,
per gripe from Joe Sunday.
1 parent3e5da0a commitc5336a8

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

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

Lines changed: 5 additions & 17 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.48 2003/11/29 19:51:59 pgsql Exp $
4+
*$PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.49 2003/12/01 18:50:19 tgl Exp $
55
*
66
*Jon Postel RIP 16 Oct 1998
77
*/
@@ -315,8 +315,8 @@ inet_set_masklen(PG_FUNCTION_ARGS)
315315
errmsg("invalid mask length: %d",bits)));
316316

317317
/* clone the original data */
318-
dst= (inet*)palloc(VARHDRSZ+sizeof(inet_struct));
319-
memcpy(dst,src,VARHDRSZ+sizeof(inet_struct));
318+
dst= (inet*)palloc(VARSIZE(src));
319+
memcpy(dst,src,VARSIZE(src));
320320

321321
ip_bits(dst)=bits;
322322

@@ -658,19 +658,13 @@ network_network(PG_FUNCTION_ARGS)
658658
inet*dst;
659659
intbyte;
660660
intbits;
661-
intmaxbytes;
662661
unsignedcharmask;
663662
unsignedchar*a,
664663
*b;
665664

666665
/* make sure any unused bits are zeroed */
667666
dst= (inet*)palloc0(VARHDRSZ+sizeof(inet_struct));
668667

669-
if (ip_family(ip)==PGSQL_AF_INET)
670-
maxbytes=4;
671-
else
672-
maxbytes=16;
673-
674668
bits=ip_bits(ip);
675669
a=ip_addr(ip);
676670
b=ip_addr(dst);
@@ -710,18 +704,12 @@ network_netmask(PG_FUNCTION_ARGS)
710704
inet*dst;
711705
intbyte;
712706
intbits;
713-
intmaxbytes;
714707
unsignedcharmask;
715708
unsignedchar*b;
716709

717710
/* make sure any unused bits are zeroed */
718711
dst= (inet*)palloc0(VARHDRSZ+sizeof(inet_struct));
719712

720-
if (ip_family(ip)==PGSQL_AF_INET)
721-
maxbytes=4;
722-
else
723-
maxbytes=16;
724-
725713
bits=ip_bits(ip);
726714
b=ip_addr(dst);
727715

@@ -744,7 +732,7 @@ network_netmask(PG_FUNCTION_ARGS)
744732
}
745733

746734
ip_family(dst)=ip_family(ip);
747-
ip_bits(dst)=ip_bits(ip);
735+
ip_bits(dst)=ip_maxbits(ip);
748736
ip_type(dst)=0;
749737
VARATT_SIZEP(dst)=VARHDRSZ
750738
+ ((char*)ip_addr(dst)- (char*)VARDATA(dst))
@@ -794,7 +782,7 @@ network_hostmask(PG_FUNCTION_ARGS)
794782
}
795783

796784
ip_family(dst)=ip_family(ip);
797-
ip_bits(dst)=ip_bits(ip);
785+
ip_bits(dst)=ip_maxbits(ip);
798786
ip_type(dst)=0;
799787
VARATT_SIZEP(dst)=VARHDRSZ
800788
+ ((char*)ip_addr(dst)- (char*)VARDATA(dst))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp