inet_recv() wasn't IPv6-ready.

This commit is contained in:
Tom Lane 2003-08-01 23:22:52 +00:00
parent ec1501395e
commit e490ee80e6

View File

@ -1,7 +1,7 @@
/* /*
* PostgreSQL type definitions for the INET and CIDR types. * PostgreSQL type definitions for the INET and CIDR types.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.43 2003/07/27 04:53:07 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.44 2003/08/01 23:22:52 tgl Exp $
* *
* Jon Postel RIP 16 Oct 1998 * Jon Postel RIP 16 Oct 1998
*/ */
@ -45,7 +45,6 @@ static int ip_addrsize(inet *inetptr);
(ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128) (ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128)
/* /*
* Now, as a function!
* Return the number of bytes of storage needed for this data type. * Return the number of bytes of storage needed for this data type.
*/ */
static int static int
@ -76,11 +75,10 @@ network_in(char *src, int type)
* if there is one present, assume it's V6, otherwise assume it's V4. * if there is one present, assume it's V6, otherwise assume it's V4.
*/ */
if (strchr(src, ':') != NULL) { if (strchr(src, ':') != NULL)
ip_family(dst) = PGSQL_AF_INET6; ip_family(dst) = PGSQL_AF_INET6;
} else { else
ip_family(dst) = PGSQL_AF_INET; ip_family(dst) = PGSQL_AF_INET;
}
bits = inet_net_pton(ip_family(dst), src, ip_addr(dst), bits = inet_net_pton(ip_family(dst), src, ip_addr(dst),
type ? ip_addrsize(dst) : -1); type ? ip_addrsize(dst) : -1);
@ -188,7 +186,8 @@ inet_recv(PG_FUNCTION_ARGS)
addr = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); addr = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct));
ip_family(addr) = pq_getmsgbyte(buf); ip_family(addr) = pq_getmsgbyte(buf);
if (ip_family(addr) != AF_INET) if (ip_family(addr) != PGSQL_AF_INET &&
ip_family(addr) != PGSQL_AF_INET6)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid family in external inet"))); errmsg("invalid family in external inet")));
@ -218,7 +217,7 @@ inet_recv(PG_FUNCTION_ARGS)
/* /*
* Error check: CIDR values must not have any bits set beyond the * Error check: CIDR values must not have any bits set beyond the
* masklen. XXX this code is not IPV6 ready. * masklen.
*/ */
if (ip_type(addr)) if (ip_type(addr))
{ {
@ -902,12 +901,10 @@ addressOK(unsigned char *a, int bits, int family)
maxbits = 128; maxbits = 128;
maxbytes = 16; maxbytes = 16;
} }
#if 0 Assert(bits <= maxbits);
assert(bits <= maxbits);
#endif
if (bits == maxbits) if (bits == maxbits)
return 1; return true;
byte = (bits + 7) / 8; byte = (bits + 7) / 8;
nbits = bits % 8; nbits = bits % 8;
@ -917,12 +914,12 @@ addressOK(unsigned char *a, int bits, int family)
while (byte < maxbytes) { while (byte < maxbytes) {
if ((a[byte] & mask) != 0) if ((a[byte] & mask) != 0)
return 0; return false;
mask = 0xff; mask = 0xff;
byte++; byte++;
} }
return 1; return true;
} }