1
1
/*
2
2
* PostgreSQL type definitions for the INET and CIDR types.
3
3
*
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 $
5
5
*
6
6
* Jon Postel RIP 16 Oct 1998
7
7
*/
@@ -45,7 +45,6 @@ static int ip_addrsize(inet *inetptr);
45
45
(ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128)
46
46
47
47
/*
48
- * Now, as a function!
49
48
* Return the number of bytes of storage needed for this data type.
50
49
*/
51
50
static int
@@ -76,11 +75,10 @@ network_in(char *src, int type)
76
75
* if there is one present, assume it's V6, otherwise assume it's V4.
77
76
*/
78
77
79
- if (strchr (src , ':' ) != NULL ) {
78
+ if (strchr (src , ':' ) != NULL )
80
79
ip_family (dst ) = PGSQL_AF_INET6 ;
81
- } else {
80
+ else
82
81
ip_family (dst ) = PGSQL_AF_INET ;
83
- }
84
82
85
83
bits = inet_net_pton (ip_family (dst ), src , ip_addr (dst ),
86
84
type ? ip_addrsize (dst ) : -1 );
@@ -188,7 +186,8 @@ inet_recv(PG_FUNCTION_ARGS)
188
186
addr = (inet * ) palloc0 (VARHDRSZ + sizeof (inet_struct ));
189
187
190
188
ip_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 )
192
191
ereport (ERROR ,
193
192
(errcode (ERRCODE_INVALID_BINARY_REPRESENTATION ),
194
193
errmsg ("invalid family in external inet" )));
@@ -218,7 +217,7 @@ inet_recv(PG_FUNCTION_ARGS)
218
217
219
218
/*
220
219
* Error check: CIDR values must not have any bits set beyond the
221
- * masklen. XXX this code is not IPV6 ready.
220
+ * masklen.
222
221
*/
223
222
if (ip_type (addr ))
224
223
{
@@ -902,12 +901,10 @@ addressOK(unsigned char *a, int bits, int family)
902
901
maxbits = 128 ;
903
902
maxbytes = 16 ;
904
903
}
905
- #if 0
906
- assert (bits <= maxbits );
907
- #endif
904
+ Assert (bits <= maxbits );
908
905
909
906
if (bits == maxbits )
910
- return 1 ;
907
+ return true ;
911
908
912
909
byte = (bits + 7 ) / 8 ;
913
910
nbits = bits % 8 ;
@@ -917,12 +914,12 @@ addressOK(unsigned char *a, int bits, int family)
917
914
918
915
while (byte < maxbytes ) {
919
916
if ((a [byte ] & mask ) != 0 )
920
- return 0 ;
917
+ return false ;
921
918
mask = 0xff ;
922
919
byte ++ ;
923
920
}
924
921
925
- return 1 ;
922
+ return true ;
926
923
}
927
924
928
925
0 commit comments