11/*
22 *PostgreSQL type definitions for the INET and CIDR types.
33 *
4- *$Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.43 2003/07/27 04:53:07 tgl Exp $
4+ *$Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.44 2003/08/01 23:22:52 tgl Exp $
55 *
66 *Jon Postel RIP 16 Oct 1998
77 */
@@ -45,7 +45,6 @@ static int ip_addrsize(inet *inetptr);
4545(ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128)
4646
4747/*
48- * Now, as a function!
4948 * Return the number of bytes of storage needed for this data type.
5049 */
5150static int
@@ -76,11 +75,10 @@ network_in(char *src, int type)
7675 * if there is one present, assume it's V6, otherwise assume it's V4.
7776 */
7877
79- if (strchr (src ,':' )!= NULL ) {
78+ if (strchr (src ,':' )!= NULL )
8079ip_family (dst )= PGSQL_AF_INET6 ;
81- } else {
80+ else
8281ip_family (dst )= PGSQL_AF_INET ;
83- }
8482
8583bits = inet_net_pton (ip_family (dst ),src ,ip_addr (dst ),
8684type ?ip_addrsize (dst ) :-1 );
@@ -188,7 +186,8 @@ inet_recv(PG_FUNCTION_ARGS)
188186addr = (inet * )palloc0 (VARHDRSZ + sizeof (inet_struct ));
189187
190188ip_family (addr )= pq_getmsgbyte (buf );
191- if (ip_family (addr )!= AF_INET )
189+ if (ip_family (addr )!= PGSQL_AF_INET &&
190+ ip_family (addr )!= PGSQL_AF_INET6 )
192191ereport (ERROR ,
193192(errcode (ERRCODE_INVALID_BINARY_REPRESENTATION ),
194193errmsg ("invalid family in external inet" )));
@@ -218,7 +217,7 @@ inet_recv(PG_FUNCTION_ARGS)
218217
219218/*
220219 * Error check: CIDR values must not have any bits set beyond the
221- * masklen. XXX this code is not IPV6 ready.
220+ * masklen.
222221 */
223222if (ip_type (addr ))
224223{
@@ -902,12 +901,10 @@ addressOK(unsigned char *a, int bits, int family)
902901maxbits = 128 ;
903902maxbytes = 16 ;
904903}
905- #if 0
906- assert (bits <=maxbits );
907- #endif
904+ Assert (bits <=maxbits );
908905
909906if (bits == maxbits )
910- return 1 ;
907+ return true ;
911908
912909byte = (bits + 7 ) /8 ;
913910nbits = bits %8 ;
@@ -917,12 +914,12 @@ addressOK(unsigned char *a, int bits, int family)
917914
918915while (byte < maxbytes ) {
919916if ((a [byte ]& mask )!= 0 )
920- return 0 ;
917+ return false ;
921918mask = 0xff ;
922919byte ++ ;
923920}
924921
925- return 1 ;
922+ return true ;
926923}
927924
928925