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)
315315errmsg ("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
321321ip_bits (dst )= bits ;
322322
@@ -658,19 +658,13 @@ network_network(PG_FUNCTION_ARGS)
658658inet * dst ;
659659int byte ;
660660int bits ;
661- int maxbytes ;
662661unsignedchar mask ;
663662unsignedchar * a ,
664663* b ;
665664
666665/* make sure any unused bits are zeroed */
667666dst = (inet * )palloc0 (VARHDRSZ + sizeof (inet_struct ));
668667
669- if (ip_family (ip )== PGSQL_AF_INET )
670- maxbytes = 4 ;
671- else
672- maxbytes = 16 ;
673-
674668bits = ip_bits (ip );
675669a = ip_addr (ip );
676670b = ip_addr (dst );
@@ -710,18 +704,12 @@ network_netmask(PG_FUNCTION_ARGS)
710704inet * dst ;
711705int byte ;
712706int bits ;
713- int maxbytes ;
714707unsignedchar mask ;
715708unsignedchar * b ;
716709
717710/* make sure any unused bits are zeroed */
718711dst = (inet * )palloc0 (VARHDRSZ + sizeof (inet_struct ));
719712
720- if (ip_family (ip )== PGSQL_AF_INET )
721- maxbytes = 4 ;
722- else
723- maxbytes = 16 ;
724-
725713bits = ip_bits (ip );
726714b = ip_addr (dst );
727715
@@ -744,7 +732,7 @@ network_netmask(PG_FUNCTION_ARGS)
744732}
745733
746734ip_family (dst )= ip_family (ip );
747- ip_bits (dst )= ip_bits (ip );
735+ ip_bits (dst )= ip_maxbits (ip );
748736ip_type (dst )= 0 ;
749737VARATT_SIZEP (dst )= VARHDRSZ
750738+ ((char * )ip_addr (dst )- (char * )VARDATA (dst ))
@@ -794,7 +782,7 @@ network_hostmask(PG_FUNCTION_ARGS)
794782}
795783
796784ip_family (dst )= ip_family (ip );
797- ip_bits (dst )= ip_bits (ip );
785+ ip_bits (dst )= ip_maxbits (ip );
798786ip_type (dst )= 0 ;
799787VARATT_SIZEP (dst )= VARHDRSZ
800788+ ((char * )ip_addr (dst )- (char * )VARDATA (dst ))