--- /dev/null
+/*
+ * PostgreSQL type definitions for the INET type. This
+ * is for IP V4 CIDR notation, but prepared for V6: just
+ * add the necessary bits where the comments indicate.
+ *
+ * $Id: network.c,v 1.1 1998/10/22 20:40:46 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>
+
+static int v4bitncmp(unsigned int a1, unsigned int a2, int bits);
+
+/*
+ * Access macros. Add IPV6 support.
+ */
+
+#define ip_addrsize(inetptr) \
+ (((inet_struct *)VARDATA(inetptr))->family == AF_INET ? 4 : -1)
+
+#define ip_family(inetptr) \
+ (((inet_struct *)VARDATA(inetptr))->family)
+
+#define ip_bits(inetptr) \
+ (((inet_struct *)VARDATA(inetptr))->bits)
+
+#define ip_type(inetptr) \
+ (((inet_struct *)VARDATA(inetptr))->type)
+
+#define ip_v4addr(inetptr) \
+ (((inet_struct *)VARDATA(inetptr))->addr.ipv4_addr)
+
+/* Common input routine */
+static inet *
+network_in(char *src, int type)
+{
+ int bits;
+ inet *dst;
+
+ dst = palloc(VARHDRSZ + sizeof(inet_struct));
+ if (dst == NULL)
+ {
+ elog(ERROR, "unable to allocate memory in network_in()");
+ return NULL;
+ }
+ /* First, try for an IP V4 address: */
+ ip_family(dst) = AF_INET;
+ bits = inet_net_pton(ip_family(dst), src, &ip_v4addr(dst),
+ type ? ip_addrsize(dst) : -1);
+ if ((bits < 0) || (bits > 32))
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "could not parse \"%s\"", src);
+ pfree(dst);
+ return NULL;
+ }
+ VARSIZE(dst) = VARHDRSZ
+ + ((char *) &ip_v4addr(dst) - (char *) VARDATA(dst))
+ + ip_addrsize(dst);
+ ip_bits(dst) = bits;
+ ip_type(dst) = type;
+ return dst;
+}
+
+/* INET address reader. */
+inet *
+inet_in(char *src)
+{
+ return network_in(src, 0);
+}
+
+/* CIDR address reader. */
+inet *
+cidr_in(char *src)
+{
+ return network_in(src, 1);
+}
+
+/*
+ * INET address output function.
+ */
+
+char *
+inet_out(inet *src)
+{
+ char *dst,
+ tmp[sizeof("255.255.255.255/32")];
+
+ if (ip_family(src) == AF_INET)
+ {
+ /* It's an IP V4 address: */
+ if (ip_type(src))
+ dst = inet_cidr_ntop(AF_INET, &ip_v4addr(src), ip_bits(src),
+ tmp, sizeof(tmp));
+ else
+ dst = inet_net_ntop(AF_INET, &ip_v4addr(src), ip_bits(src),
+ tmp, sizeof(tmp));
+
+ if (dst == NULL)
+ {
+ elog(ERROR, "unable to print address (%s)", strerror(errno));
+ return (NULL);
+ }
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "unknown address family (%d)", ip_family(src));
+ return NULL;
+ }
+ dst = palloc(strlen(tmp) + 1);
+ if (dst == NULL)
+ {
+ elog(ERROR, "unable to allocate memory in inet_out()");
+ return NULL;
+ }
+ strcpy(dst, tmp);
+ return dst;
+}
+
+
+/* just a stub */
+char *
+cidr_out(inet *src)
+{
+ return inet_out(src);
+}
+
+/*
+ * Boolean tests for magnitude. Add V4/V6 testing!
+ */
+
+bool
+network_lt(inet *a1, inet *a2)
+{
+ if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET))
+ {
+ int order = v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2));
+
+ return ((order < 0) || ((order == 0) && (ip_bits(a1) < ip_bits(a2))));
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "cannot compare address families %d and %d",
+ ip_family(a1), ip_family(a2));
+ return (FALSE);
+ }
+}
+
+bool
+network_le(inet *a1, inet *a2)
+{
+ return (network_lt(a1, a2) || network_eq(a1, a2));
+}
+
+bool
+network_eq(inet *a1, inet *a2)
+{
+ if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET))
+ {
+ return ((ip_bits(a1) == ip_bits(a2))
+ && (v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0));
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "cannot compare address families %d and %d",
+ ip_family(a1), ip_family(a2));
+ return (FALSE);
+ }
+}
+
+bool
+network_ge(inet *a1, inet *a2)
+{
+ return (network_gt(a1, a2) || network_eq(a1, a2));
+}
+
+bool
+network_gt(inet *a1, inet *a2)
+{
+ if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET))
+ {
+ int order = v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2));
+
+ return ((order > 0) || ((order == 0) && (ip_bits(a1) > ip_bits(a2))));
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "cannot compare address families %d and %d",
+ ip_family(a1), ip_family(a2));
+ return (FALSE);
+ }
+}
+
+bool
+network_ne(inet *a1, inet *a2)
+{
+ return (!network_eq(a1, a2));
+}
+
+bool
+network_sub(inet *a1, inet *a2)
+{
+ if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET))
+ {
+ return ((ip_bits(a1) > ip_bits(a2))
+ && (v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0));
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "cannot compare address families %d and %d",
+ ip_family(a1), ip_family(a2));
+ return (FALSE);
+ }
+}
+
+bool
+network_subeq(inet *a1, inet *a2)
+{
+ if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET))
+ {
+ return ((ip_bits(a1) >= ip_bits(a2))
+ && (v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0));
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "cannot compare address families %d and %d",
+ ip_family(a1), ip_family(a2));
+ return (FALSE);
+ }
+}
+
+bool
+network_sup(inet *a1, inet *a2)
+{
+ if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET))
+ {
+ return ((ip_bits(a1) < ip_bits(a2))
+ && (v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0));
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "cannot compare address families %d and %d",
+ ip_family(a1), ip_family(a2));
+ return (FALSE);
+ }
+}
+
+bool
+network_supeq(inet *a1, inet *a2)
+{
+ if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET))
+ {
+ return ((ip_bits(a1) <= ip_bits(a2))
+ && (v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0));
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "cannot compare address families %d and %d",
+ ip_family(a1), ip_family(a2));
+ return (FALSE);
+ }
+}
+
+/*
+ * Comparison function for sorting. Add V4/V6 testing!
+ */
+
+int4
+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)))
+ return (1);
+ return 0;
+}
+
+text *
+network_host(inet *ip)
+{
+ text *ret;
+ int len;
+ char *ptr,
+ tmp[sizeof("255.255.255.255/32")];
+
+ if (ip_type(ip))
+ {
+ elog(ERROR, "CIDR type has no host part");
+ return NULL;
+ }
+
+ if (ip_family(ip) == AF_INET)
+ {
+ /* It's an IP V4 address: */
+ if (inet_net_ntop(AF_INET, &ip_v4addr(ip), 32, tmp, sizeof(tmp)) < 0)
+ {
+ elog(ERROR, "unable to print host (%s)", strerror(errno));
+ return (NULL);
+ }
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "unknown address family (%d)", ip_family(ip));
+ return (NULL);
+ }
+ if ((ptr = strchr(tmp, '/')) != NULL)
+ *ptr = 0;
+ len = VARHDRSZ + strlen(tmp) + 1;
+ ret = palloc(len);
+ if (ret == NULL)
+ {
+ elog(ERROR, "unable to allocate memory in network_host()");
+ return (NULL);
+ }
+ VARSIZE(ret) = len;
+ strcpy(VARDATA(ret), tmp);
+ return (ret);
+}
+
+int4
+network_masklen(inet *ip)
+{
+ return ip_bits(ip);
+}
+
+text *
+network_broadcast(inet *ip)
+{
+ text *ret;
+ int len;
+ char *ptr,
+ tmp[sizeof("255.255.255.255/32")];
+
+ if (ip_family(ip) == AF_INET)
+ {
+ /* It's an IP V4 address: */
+ int addr = htonl(ntohl(ip_v4addr(ip)) | (0xffffffff >> ip_bits(ip)));
+
+ if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) < 0)
+ {
+ elog(ERROR, "unable to print address (%s)", strerror(errno));
+ return (NULL);
+ }
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "unknown address family (%d)", ip_family(ip));
+ return (NULL);
+ }
+ if ((ptr = strchr(tmp, '/')) != NULL)
+ *ptr = 0;
+ len = VARHDRSZ + strlen(tmp) + 1;
+ ret = palloc(len);
+ if (ret == NULL)
+ {
+ elog(ERROR, "unable to allocate memory in network_broadcast()");
+ return (NULL);
+ }
+ VARSIZE(ret) = len;
+ strcpy(VARDATA(ret), tmp);
+ return (ret);
+}
+
+text *
+network_network(inet *ip)
+{
+ text *ret;
+ int len;
+ char *ptr,
+ tmp[sizeof("255.255.255.255/32")];
+
+ if (ip_family(ip) == AF_INET)
+ {
+ /* It's an IP V4 address: */
+ int addr = ntohl(ip_v4addr(ip)) & (0xffffffff << (32 - ip_bits(ip)));
+
+ if (inet_cidr_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) < 0)
+ {
+ elog(ERROR, "unable to print network (%s)", strerror(errno));
+ return (NULL);
+ }
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "unknown address family (%d)", ip_family(ip));
+ return (NULL);
+ }
+ if ((ptr = strchr(tmp, '/')) != NULL)
+ *ptr = 0;
+ len = VARHDRSZ + strlen(tmp) + 1;
+ ret = palloc(len);
+ if (ret == NULL)
+ {
+ elog(ERROR, "unable to allocate memory in network_network()");
+ return (NULL);
+ }
+ VARSIZE(ret) = len;
+ strcpy(VARDATA(ret), tmp);
+ return (ret);
+}
+
+text *
+network_netmask(inet *ip)
+{
+ text *ret;
+ int len;
+ char *ptr,
+ tmp[sizeof("255.255.255.255/32")];
+
+ if (ip_family(ip) == AF_INET)
+ {
+ /* It's an IP V4 address: */
+ int addr = htonl((-1 << (32 - ip_bits(ip))) & 0xffffffff);
+
+ if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) < 0)
+ {
+ elog(ERROR, "unable to print netmask (%s)", strerror(errno));
+ return (NULL);
+ }
+ }
+ else
+ {
+ /* Go for an IPV6 address here, before faulting out: */
+ elog(ERROR, "unknown address family (%d)", ip_family(ip));
+ return (NULL);
+ }
+ if ((ptr = strchr(tmp, '/')) != NULL)
+ *ptr = 0;
+ len = VARHDRSZ + strlen(tmp) + 1;
+ ret = palloc(len);
+ if (ret == NULL)
+ {
+ elog(ERROR, "unable to allocate memory in network_netmask()");
+ return (NULL);
+ }
+ VARSIZE(ret) = len;
+ strcpy(VARDATA(ret), tmp);
+ return (ret);
+}
+
+/*
+ * Bitwise comparison for V4 addresses. Add V6 implementation!
+ */
+
+static int
+v4bitncmp(unsigned int a1, unsigned int a2, int bits)
+{
+ unsigned long mask = 0;
+ int i;
+
+ for (i = 0; i < bits; i++)
+ mask = (mask >> 1) | 0x80000000;
+ a1 = ntohl(a1);
+ a2 = ntohl(a2);
+ if ((a1 & mask) < (a2 & mask))
+ return (-1);
+ else if ((a1 & mask) > (a2 & mask))
+ return (1);
+ return (0);
+}
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_operator.h,v 1.42 1998/10/22 13:51:00 momjian Exp $
+ * $Id: pg_operator.h,v 1.43 1998/10/22 20:40:47 momjian Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
DATA(insert OID = 1225 ( ">=" PGUID 0 b t f 829 829 16 1223 1222 0 0 macaddr_ge intltsel intltjoinsel ));
/* INET type */
-DATA(insert OID = 1201 ( "=" PGUID 0 b t t 869 869 16 1201 1202 0 0 inet_eq eqsel eqjoinsel ));
-DATA(insert OID = 1202 ( "<>" PGUID 0 b t f 869 869 16 1202 1201 0 0 inet_ne neqsel neqjoinsel ));
-DATA(insert OID = 1203 ( "<" PGUID 0 b t f 869 869 16 1205 1206 0 0 inet_lt intltsel intltjoinsel ));
-DATA(insert OID = 1204 ( "<=" PGUID 0 b t f 869 869 16 1206 1205 0 0 inet_le intltsel intltjoinsel ));
-DATA(insert OID = 1205 ( ">" PGUID 0 b t f 869 869 16 1203 1204 0 0 inet_gt intltsel intltjoinsel ));
-DATA(insert OID = 1206 ( ">=" PGUID 0 b t f 869 869 16 1204 1203 0 0 inet_ge intltsel intltjoinsel ));
-DATA(insert OID = 931 ( "<<" PGUID 0 b t f 869 869 16 933 934 0 0 inet_sub intltsel intltjoinsel ));
-DATA(insert OID = 932 ( "<<=" PGUID 0 b t f 869 869 16 934 933 0 0 inet_subeq intltsel intltjoinsel ));
-DATA(insert OID = 933 ( ">>" PGUID 0 b t f 869 869 16 931 932 0 0 inet_sup intltsel intltjoinsel ));
-DATA(insert OID = 934 ( ">>=" PGUID 0 b t f 869 869 16 932 931 0 0 inet_supeq intltsel intltjoinsel ));
+DATA(insert OID = 1201 ( "=" PGUID 0 b t t 869 869 16 1201 1202 0 0 network_eq eqsel eqjoinsel ));
+DATA(insert OID = 1202 ( "<>" PGUID 0 b t f 869 869 16 1202 1201 0 0 network_ne neqsel neqjoinsel ));
+DATA(insert OID = 1203 ( "<" PGUID 0 b t f 869 869 16 1205 1206 0 0 network_lt intltsel intltjoinsel ));
+DATA(insert OID = 1204 ( "<=" PGUID 0 b t f 869 869 16 1206 1205 0 0 network_le intltsel intltjoinsel ));
+DATA(insert OID = 1205 ( ">" PGUID 0 b t f 869 869 16 1203 1204 0 0 network_gt intltsel intltjoinsel ));
+DATA(insert OID = 1206 ( ">=" PGUID 0 b t f 869 869 16 1204 1203 0 0 network_ge intltsel intltjoinsel ));
+DATA(insert OID = 931 ( "<<" PGUID 0 b t f 869 869 16 933 934 0 0 network_sub intltsel intltjoinsel ));
+DATA(insert OID = 932 ( "<<=" PGUID 0 b t f 869 869 16 934 933 0 0 network_subeq intltsel intltjoinsel ));
+DATA(insert OID = 933 ( ">>" PGUID 0 b t f 869 869 16 931 932 0 0 network_sup intltsel intltjoinsel ));
+DATA(insert OID = 934 ( ">>=" PGUID 0 b t f 869 869 16 932 931 0 0 network_supeq intltsel intltjoinsel ));
/* CIDR type */
-DATA(insert OID = 820 ( "=" PGUID 0 b t t 650 650 16 820 821 0 0 inet_eq eqsel eqjoinsel ));
-DATA(insert OID = 821 ( "<>" PGUID 0 b t f 650 650 16 821 820 0 0 inet_ne neqsel neqjoinsel ));
-DATA(insert OID = 822 ( "<" PGUID 0 b t f 650 650 16 824 825 0 0 inet_lt intltsel intltjoinsel ));
-DATA(insert OID = 823 ( "<=" PGUID 0 b t f 650 650 16 825 824 0 0 inet_le intltsel intltjoinsel ));
-DATA(insert OID = 824 ( ">" PGUID 0 b t f 650 650 16 822 823 0 0 inet_gt intltsel intltjoinsel ));
-DATA(insert OID = 825 ( ">=" PGUID 0 b t f 650 650 16 823 822 0 0 inet_ge intltsel intltjoinsel ));
-DATA(insert OID = 826 ( "<<" PGUID 0 b t f 650 650 16 828 1004 0 0 inet_sub intltsel intltjoinsel ));
-DATA(insert OID = 827 ( "<<=" PGUID 0 b t f 650 650 16 1004 828 0 0 inet_subeq intltsel intltjoinsel ));
-DATA(insert OID = 828 ( ">>" PGUID 0 b t f 650 650 16 826 827 0 0 inet_sup intltsel intltjoinsel ));
-DATA(insert OID = 1004 ( ">>=" PGUID 0 b t f 650 650 16 827 826 0 0 inet_supeq intltsel intltjoinsel ));
+DATA(insert OID = 820 ( "=" PGUID 0 b t t 650 650 16 820 821 0 0 network_eq eqsel eqjoinsel ));
+DATA(insert OID = 821 ( "<>" PGUID 0 b t f 650 650 16 821 820 0 0 network_ne neqsel neqjoinsel ));
+DATA(insert OID = 822 ( "<" PGUID 0 b t f 650 650 16 824 825 0 0 network_lt intltsel intltjoinsel ));
+DATA(insert OID = 823 ( "<=" PGUID 0 b t f 650 650 16 825 824 0 0 network_le intltsel intltjoinsel ));
+DATA(insert OID = 824 ( ">" PGUID 0 b t f 650 650 16 822 823 0 0 network_gt intltsel intltjoinsel ));
+DATA(insert OID = 825 ( ">=" PGUID 0 b t f 650 650 16 823 822 0 0 network_ge intltsel intltjoinsel ));
+DATA(insert OID = 826 ( "<<" PGUID 0 b t f 650 650 16 828 1004 0 0 network_sub intltsel intltjoinsel ));
+DATA(insert OID = 827 ( "<<=" PGUID 0 b t f 650 650 16 1004 828 0 0 network_subeq intltsel intltjoinsel ));
+DATA(insert OID = 828 ( ">>" PGUID 0 b t f 650 650 16 826 827 0 0 network_sup intltsel intltjoinsel ));
+DATA(insert OID = 1004 ( ">>=" PGUID 0 b t f 650 650 16 827 826 0 0 network_supeq intltsel intltjoinsel ));
/*
* function prototypes
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_proc.h,v 1.80 1998/10/22 13:51:02 momjian Exp $
+ * $Id: pg_proc.h,v 1.81 1998/10/22 20:40:49 momjian Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
DESCR("(internal)");
/* these are used for both inet and cidr */
-DATA(insert OID = 920 ( inet_eq PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 920 ( network_eq PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("equal");
-DATA(insert OID = 921 ( inet_lt PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 921 ( network_lt PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("less-than");
-DATA(insert OID = 922 ( inet_le PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 922 ( network_le PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("less-than-or-equal");
-DATA(insert OID = 923 ( inet_gt PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 923 ( network_gt PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("greater-than");
-DATA(insert OID = 924 ( inet_ge PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 924 ( network_ge PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("greater-than-or-equal");
-DATA(insert OID = 925 ( inet_ne PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 925 ( network_ne PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("not equal");
-DATA(insert OID = 926 ( inet_cmp PGUID 11 f t f 2 f 23 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 926 ( network_cmp PGUID 11 f t f 2 f 23 "869 869" 100 0 0 100 foo bar ));
DESCR("less-equal-greater");
-DATA(insert OID = 927 ( inet_sub PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 927 ( network_sub PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("is-subnet");
-DATA(insert OID = 928 ( inet_subeq PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 928 ( network_subeq PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("is-subnet-or-equal");
-DATA(insert OID = 929 ( inet_sup PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 929 ( network_sup PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("is-supernet");
-DATA(insert OID = 930 ( inet_supeq PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
+DATA(insert OID = 930 ( network_supeq PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100 foo bar ));
DESCR("is-supernet-or-equal");
/* inet/cidr versions */
-DATA(insert OID = 940 ( netmask PGUID 11 f t f 1 f 25 "869" 100 0 0 100 foo bar ));
+DATA(insert OID = 940 ( network_netmask PGUID 11 f t f 1 f 25 "869" 100 0 0 100 foo bar ));
DESCR("netmask of address");
-DATA(insert OID = 941 ( masklen PGUID 11 f t f 1 f 23 "869" 100 0 0 100 foo bar ));
+DATA(insert OID = 941 ( network_masklen PGUID 11 f t f 1 f 23 "869" 100 0 0 100 foo bar ));
DESCR("netmask length");
-DATA(insert OID = 945 ( broadcast PGUID 11 f t f 1 f 25 "869" 100 0 0 100 foo bar ));
+DATA(insert OID = 945 ( network_broadcast PGUID 11 f t f 1 f 25 "869" 100 0 0 100 foo bar ));
DESCR("broadcast address");
-DATA(insert OID = 682 ( host PGUID 11 f t f 1 f 25 "869" 100 0 0 100 foo bar ));
+DATA(insert OID = 682 ( network_host PGUID 11 f t f 1 f 25 "869" 100 0 0 100 foo bar ));
DESCR("host address");
+DATA(insert OID = 473 ( network_network PGUID 11 f t f 1 f 25 "869" 100 0 0 100 foo bar ));
+DESCR("network address");
+/* shortcut names */
+DATA(insert OID = 696 ( netmask PGUID 14 f t f 1 f 25 "869" 100 0 0 100 "select network_netmask($1)" - ));
+DESCR("netmask of address");
+DATA(insert OID = 697 ( masklen PGUID 14 f t f 1 f 23 "869" 100 0 0 100 "select network_masklen($1)" - ));
+DESCR("netmask length");
+DATA(insert OID = 698 ( broadcast PGUID 14 f t f 1 f 25 "869" 100 0 0 100 "select network_broadcast($1)" - ));
+DESCR("broadcast address");
+DATA(insert OID = 699 ( host PGUID 14 f t f 1 f 25 "869" 100 0 0 100 "select network_host($1)" - ));
+DESCR("host address");
+DATA(insert OID = 683 ( network PGUID 14 f t f 1 f 25 "869" 100 0 0 100 "select network_network($1)" - ));
+DESCR("network address");
/*
* prototypes for functions pg_proc.c
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: builtins.h,v 1.67 1998/10/22 13:51:07 momjian Exp $
+ * $Id: builtins.h,v 1.68 1998/10/22 20:40:50 momjian Exp $
*
* NOTES
* This should normally only be included by fmgr.h.
/* inet_net_pton.c */
int inet_net_pton(int af, const char *src, void *dst, size_t size);
-/* inet.c */
+/* network.c */
inet *inet_in(char *str);
char *inet_out(inet * addr);
inet *cidr_in(char *str);
char *cidr_out(inet *addr);
-bool inet_lt(inet * a1, inet * a2);
-bool inet_le(inet * a1, inet * a2);
-bool inet_eq(inet * a1, inet * a2);
-bool inet_ge(inet * a1, inet * a2);
-bool inet_gt(inet * a1, inet * a2);
-bool inet_ne(inet * a1, inet * a2);
-bool inet_sub(inet * a1, inet * a2);
-bool inet_subeq(inet * a1, inet * a2);
-bool inet_sup(inet * a1, inet * a2);
-bool inet_supeq(inet * a1, inet * a2);
-int4 inet_cmp(inet * a1, inet * a2);
-
-text *netmask(inet * addr);
-int4 masklen(inet * addr);
-text *broadcast(inet * addr);
-text *host(inet * addr);
+bool network_lt(inet * a1, inet * a2);
+bool network_le(inet * a1, inet * a2);
+bool network_eq(inet * a1, inet * a2);
+bool network_ge(inet * a1, inet * a2);
+bool network_gt(inet * a1, inet * a2);
+bool network_ne(inet * a1, inet * a2);
+bool network_sub(inet * a1, inet * a2);
+bool network_subeq(inet * a1, inet * a2);
+bool network_sup(inet * a1, inet * a2);
+bool network_supeq(inet * a1, inet * a2);
+int4 network_cmp(inet * a1, inet * a2);
+
+text *network_network(inet * addr);
+text *network_netmask(inet * addr);
+int4 network_masklen(inet * addr);
+text *network_broadcast(inet * addr);
+text *network_host(inet * addr);
/* mac.c */
macaddr *macaddr_in(char *str);