]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/network.c
Move some system includes into c.h, and remove duplicates.
[postgresql] / src / backend / utils / adt / network.c
index cd86ec6f3d5909256c398d24ca22d843bc988dc1..92580cfe965fc77fea35637a7977ee344e064f0d 100644 (file)
@@ -3,24 +3,20 @@
  *     is for IP V4 CIDR notation, but prepared for V6: just
  *     add the necessary bits where the comments indicate.
  *
- *     $Id: network.c,v 1.9 1999/05/25 16:12:11 momjian Exp $
+ *     $Id: network.c,v 1.15 1999/07/17 20:17:58 momjian Exp $
  *     Jon Postel RIP 16 Oct 1998
  */
 
 #include <sys/types.h>
 #include <sys/socket.h>
 
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-#include <postgres.h>
-#include <utils/palloc.h>
-#include <utils/builtins.h>
-#include <utils/inet.h>
+#include "postgres.h"
+#include "utils/builtins.h"
 
 static int     v4bitncmp(unsigned int a1, unsigned int a2, int bits);
 
@@ -306,8 +302,16 @@ network_cmp(inet *a1, inet *a2)
 {
        if (ntohl(ip_v4addr(a1)) < ntohl(ip_v4addr(a2)))
                return (-1);
-       else if (ntohl(ip_v4addr(a1)) > ntohl(ip_v4addr(a2)))
+
+       if (ntohl(ip_v4addr(a1)) > ntohl(ip_v4addr(a2)))
+               return (1);
+
+       if (ip_bits(a1) < ip_bits(a2))
+               return (-1);
+
+       if (ip_bits(a1) > ip_bits(a2))
                return (1);
+
        return 0;
 }