From dabc3f31b583c4c1b75f62a7a764086557b1559c Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Thu, 23 Sep 1999 17:42:23 +0000
Subject: [PATCH] Fix for netmask('x.x.x.x/0') is 255.255.255.255 instead of
 0.0.0.0 This is because (-1) << 32 is -1 (Only intel arc. has been checked)

Oleg Sharoiko
---
 doc/TODO                        | 1 +
 src/backend/utils/adt/network.c | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/TODO b/doc/TODO
index 0930c695f0..1e6fdaef0d 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -48,6 +48,7 @@ PARSER
 * redesign INSERT ... SELECT to have two levels of target list
 * -select * from pg_class where oid in (0,-1)
 * have INTERSECT/EXCEPT prevent duplicates unless ALL is specified
+* prevent primary key of nine columns(see TODO.detail/primary)
 
 VIEWS
 
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 92580cfe96..cb1b9b90bf 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -3,7 +3,7 @@
  *	is for IP V4 CIDR notation, but prepared for V6: just
  *	add the necessary bits where the comments indicate.
  *
- *	$Id: network.c,v 1.15 1999/07/17 20:17:58 momjian Exp $
+ *	$Id: network.c,v 1.16 1999/09/23 17:42:23 momjian Exp $
  *	Jon Postel RIP 16 Oct 1998
  */
 
@@ -448,7 +448,8 @@ network_netmask(inet *ip)
 	if (ip_family(ip) == AF_INET)
 	{
 		/* It's an IP V4 address: */
-		int			addr = htonl((-1 << (32 - ip_bits(ip))) & 0xffffffff);
+		int	addr = htonl(ip_bits(ip) ?
+			(-1 << (32 - ip_bits(ip))) & 0xffffffff : 0x00000000);
 
 		if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) == NULL)
 			elog(ERROR, "unable to print netmask (%s)", strerror(errno));
-- 
2.24.1