Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] Re: CIDR/IP types. Was: [GENERAL] big numbers

From: Tom Ivar Helbekkmo <tih(at)nhh(dot)no>
To: "Marc G(dot) Fournier" <scrappy(at)hub(dot)org>
Cc: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>, Tom Ivar Helbekkmo <tih(at)nhh(dot)no>, PostgreSQL-development <hackers(at)postgreSQL(dot)org>
Subject: Re: [HACKERS] Re: CIDR/IP types. Was: [GENERAL] big numbers
Date: 1998-10-07 09:28:08
Message-ID: 86r9wkyb4n.fsf@athene.nhh.no (view raw or flat)
Thread:
Lists: pgsql-hackers
"Marc G. Fournier" <scrappy(at)hub(dot)org> writes:

> 	*Please* make the appropriate changes and submit a patch...it
> should be listed as CIDR, not as IPADDR.  MACADDR, IMHO, is okay, as its
> the only way I've ever heard of it being referred...but I do not consider
> IPADDR to be correct terminology...

I agree.  I think, though, that the best argument presented in the
debate was from Paul Vixie, who wanted INET to be the name covering
both IPV4 and IPV6.  The following kit makes the needed changes:

WARNING!  This posting contains two separate patch kits, to be applied
at different times, renaming a couple of files in between them!  The
steps to be taken are marked with "[***]".

[***] First apply these patches to change ipaddr to inet.  Affected files are:

- src/backend/utils/adt/ip.c
- src/include/catalog/pg_opclass.h
- src/include/catalog/pg_operator.h
- src/include/catalog/pg_proc.h
- src/include/catalog/pg_type.h
- src/include/utils/builtins.h
- src/include/utils/mac.h
- src/tools/pgindent/pgindent

Index: src/backend/utils/adt/ip.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/backend/utils/adt/ip.c,v
retrieving revision 1.4
diff -r1.4 ip.c
2c2
<  *	PostgreSQL type definitions for IP addresses.  This
---
>  *	PostgreSQL type definitions for the INET type.  This
23a24,25
> static int v4bitncmp(unsigned int a1, unsigned int a2, int bits);
> 
28,29c30,31
< #define ip_addrsize(ipaddrptr) \
< 	(((ipaddr_struct *)VARDATA(ipaddrptr))->family == AF_INET ? 4 : -1)
---
> #define ip_addrsize(inetptr) \
> 	(((inet_struct *)VARDATA(inetptr))->family == AF_INET ? 4 : -1)
31,32c33,34
< #define ip_family(ipaddrptr) \
< 	(((ipaddr_struct *)VARDATA(ipaddrptr))->family)
---
> #define ip_family(inetptr) \
> 	(((inet_struct *)VARDATA(inetptr))->family)
34,35c36,37
< #define ip_bits(ipaddrptr) \
< 	(((ipaddr_struct *)VARDATA(ipaddrptr))->bits)
---
> #define ip_bits(inetptr) \
> 	(((inet_struct *)VARDATA(inetptr))->bits)
37,38c39,40
< #define ip_v4addr(ipaddrptr) \
< 	(((ipaddr_struct *)VARDATA(ipaddrptr))->addr.ipv4_addr)
---
> #define ip_v4addr(inetptr) \
> 	(((inet_struct *)VARDATA(inetptr))->addr.ipv4_addr)
44,45c46,47
< ipaddr *
< ipaddr_in(char *src)
---
> inet *
> inet_in(char *src)
48c50
< 	ipaddr	   *dst;
---
> 	inet	   *dst;
50c52
< 	dst = palloc(VARHDRSZ + sizeof(ipaddr_struct));
---
> 	dst = palloc(VARHDRSZ + sizeof(inet_struct));
53c55
< 		elog(ERROR, "unable to allocate memory in ipaddr_in()");
---
> 		elog(ERROR, "unable to allocate memory in inet_in()");
78c80
< ipaddr_out(ipaddr *src)
---
> inet_out(inet *src)
102c104
< 		elog(ERROR, "unable to allocate memory in ipaddr_out()");
---
> 		elog(ERROR, "unable to allocate memory in inet_out()");
114c116
< ipaddr_lt(ipaddr *a1, ipaddr *a2)
---
> inet_lt(inet *a1, inet *a2)
132c134
< ipaddr_le(ipaddr *a1, ipaddr *a2)
---
> inet_le(inet *a1, inet *a2)
134c136
< 	return (ipaddr_lt(a1, a2) || ipaddr_eq(a1, a2));
---
> 	return (inet_lt(a1, a2) || inet_eq(a1, a2));
138c140
< ipaddr_eq(ipaddr *a1, ipaddr *a2)
---
> inet_eq(inet *a1, inet *a2)
155c157
< ipaddr_ge(ipaddr *a1, ipaddr *a2)
---
> inet_ge(inet *a1, inet *a2)
157c159
< 	return (ipaddr_gt(a1, a2) || ipaddr_eq(a1, a2));
---
> 	return (inet_gt(a1, a2) || inet_eq(a1, a2));
161c163
< ipaddr_gt(ipaddr *a1, ipaddr *a2)
---
> inet_gt(inet *a1, inet *a2)
179c181
< ipaddr_ne(ipaddr *a1, ipaddr *a2)
---
> inet_ne(inet *a1, inet *a2)
181c183
< 	return (!ipaddr_eq(a1, a2));
---
> 	return (!inet_eq(a1, a2));
185c187
< ipaddr_sub(ipaddr *a1, ipaddr *a2)
---
> inet_sub(inet *a1, inet *a2)
202c204
< ipaddr_subeq(ipaddr *a1, ipaddr *a2)
---
> inet_subeq(inet *a1, inet *a2)
219c221
< ipaddr_sup(ipaddr *a1, ipaddr *a2)
---
> inet_sup(inet *a1, inet *a2)
236c238
< ipaddr_supeq(ipaddr *a1, ipaddr *a2)
---
> inet_supeq(inet *a1, inet *a2)
257c259
< ipaddr_cmp(ipaddr *a1, ipaddr *a2)
---
> inet_cmp(inet *a1, inet *a2)
270c272
< int
---
> static int
Index: src/include/catalog/pg_opclass.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/catalog/pg_opclass.h,v
retrieving revision 1.12
diff -r1.12 pg_opclass.h
112c112
< DATA(insert OID = 935  (	ipaddr_ops   869   ));
---
> DATA(insert OID = 935  (	inet_ops   869   ));
Index: src/include/catalog/pg_operator.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/catalog/pg_operator.h,v
retrieving revision 1.39
diff -r1.39 pg_operator.h
647,656c647,656
< DATA(insert OID = 1201 (  "="	   PGUID 0 b t t 869 869	 16 1201 1202 0 0 ipaddr_eq eqsel eqjoinsel ));
< DATA(insert OID = 1202 (  "<>"	   PGUID 0 b t f 869 869	 16 1202 1201 0 0 ipaddr_ne neqsel neqjoinsel ));
< DATA(insert OID = 1203 (  "<"	   PGUID 0 b t f 869 869	 16 1205 1206 0 0 ipaddr_lt intltsel intltjoinsel ));
< DATA(insert OID = 1204 (  "<="	   PGUID 0 b t f 869 869	 16 1206 1205 0 0 ipaddr_le intltsel intltjoinsel ));
< DATA(insert OID = 1205 (  ">"	   PGUID 0 b t f 869 869	 16 1203 1204 0 0 ipaddr_gt intltsel intltjoinsel ));
< DATA(insert OID = 1206 (  ">="	   PGUID 0 b t f 869 869	 16 1204 1203 0 0 ipaddr_ge intltsel intltjoinsel ));
< DATA(insert OID = 931  (  "<<"	   PGUID 0 b t f 869 869     16 933  934  0 0 ipaddr_sub intltsel intltjoinsel ));
< DATA(insert OID = 932  (  "<<="	   PGUID 0 b t f 869 869     16 934  933  0 0 ipaddr_subeq intltsel intltjoinsel ));
< DATA(insert OID = 933  (  ">>"	   PGUID 0 b t f 869 869     16 931  932  0 0 ipaddr_sup intltsel intltjoinsel ));
< DATA(insert OID = 934  (  ">>="	   PGUID 0 b t f 869 869     16 932  931  0 0 ipaddr_supeq intltsel intltjoinsel ));
---
> 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 ));
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.71
diff -r1.71 pg_proc.h
2072c2072
< DATA(insert OID = 910 (  ipaddr_in			PGUID 11 f t f 1 f 869 "0" 100 0 0 100	foo bar ));
---
> DATA(insert OID = 910 (  inet_in			PGUID 11 f t f 1 f 869 "0" 100 0 0 100	foo bar ));
2074c2074
< DATA(insert OID = 911 (  ipaddr_out			PGUID 11 f t f 1 f 23 "0" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 911 (  inet_out			PGUID 11 f t f 1 f 23 "0" 100 0 0 100  foo bar ));
2077c2077
< DATA(insert OID = 920 (  ipaddr_eq		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 920 (  inet_eq		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2079c2079
< DATA(insert OID = 921 (  ipaddr_lt		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 921 (  inet_lt		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2081c2081
< DATA(insert OID = 922 (  ipaddr_le		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 922 (  inet_le		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2083c2083
< DATA(insert OID = 923 (  ipaddr_gt		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 923 (  inet_gt		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2085c2085
< DATA(insert OID = 924 (  ipaddr_ge		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 924 (  inet_ge		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2087c2087
< DATA(insert OID = 925 (  ipaddr_ne		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 925 (  inet_ne		   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2089c2089
< DATA(insert OID = 926 (  ipaddr_cmp	   	   PGUID 11 f t f 2 f 23 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 926 (  inet_cmp	   	   PGUID 11 f t f 2 f 23 "869 869" 100 0 0 100  foo bar ));
2091c2091
< DATA(insert OID = 927 (  ipaddr_sub	   	   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 927 (  inet_sub	   	   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2093c2093
< DATA(insert OID = 928 (  ipaddr_subeq  	   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 928 (  inet_subeq  	   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2095c2095
< DATA(insert OID = 929 (  ipaddr_sup	   	   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 929 (  inet_sup	   	   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
2097c2097
< DATA(insert OID = 930 (  ipaddr_supeq  	   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
---
> DATA(insert OID = 930 (  inet_supeq  	   PGUID 11 f t f 2 f 16 "869 869" 100 0 0 100  foo bar ));
Index: src/include/catalog/pg_type.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/catalog/pg_type.h,v
retrieving revision 1.48
diff -r1.48 pg_type.h
303c303
< DATA(insert OID = 869 ( ipaddr	   PGUID  -1 -1 f b t \054 0 0 ipaddr_in ipaddr_out ipaddr_in ipaddr_out i _null_ ));
---
> DATA(insert OID = 869 ( inet	   PGUID  -1 -1 f b t \054 0 0 inet_in inet_out inet_in inet_out i _null_ ));
342c342
< DATA(insert OID = 1041 (  _ipaddr    PGUID -1 -1 f b t \054 0  869 array_in array_out array_in array_out i _null_ ));
---
> DATA(insert OID = 1041 (  _inet    PGUID -1 -1 f b t \054 0  869 array_in array_out array_in array_out i _null_ ));
Index: src/include/utils/builtins.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/utils/builtins.h,v
retrieving revision 1.57
diff -r1.57 builtins.h
522,535c522,534
< ipaddr	   *ipaddr_in(char *str);
< char	   *ipaddr_out(ipaddr * addr);
< bool		ipaddr_lt(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_le(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_eq(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_ge(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_gt(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_ne(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_sub(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_subeq(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_sup(ipaddr * a1, ipaddr * a2);
< bool		ipaddr_supeq(ipaddr * a1, ipaddr * a2);
< int4		ipaddr_cmp(ipaddr * a1, ipaddr * a2);
< int			v4bitncmp(unsigned int a1, unsigned int a2, int bits);
---
> inet	   *inet_in(char *str);
> char	   *inet_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);
Index: src/include/utils/mac.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/include/utils/mac.h,v
retrieving revision 1.2
diff -r1.2 mac.h
29c29
< }			ipaddr_struct;
---
> }			inet_struct;
31c31
< typedef struct varlena ipaddr;
---
> typedef struct varlena inet;
Index: src/tools/pgindent/pgindent
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/tools/pgindent/pgindent,v
retrieving revision 1.11
diff -r1.11 pgindent
789c789
< -Tipaddr \
---
> -Tinet \

[***] Then, some renaming is in order:

- rename doc/README.ipaddr to doc/README.inet
- rename src/backend/utils/adt/ip.c to src/backend/utils/adt/inet.c
- rename src/include/utils/mac.h to src/include/utils/network.h

[***] Finally, apply these patches to reflect the renaming.  Files are:

- src/backend/utils/adt/Makefile
- src/backend/utils/adt/inet.c
- src/backend/utils/adt/mac.c
- src/include/utils/builtins.h

*** src/backend/utils/adt/Makefile.old	Wed Oct  7 10:45:34 1998
--- src/backend/utils/adt/Makefile	Wed Oct  7 10:46:38 1998
***************
*** 24,30 ****
  	oid.o oracle_compat.o \
  	regexp.o regproc.o ruleutils.o selfuncs.o sets.o \
  	tid.o timestamp.o varchar.o varlena.o version.o \
! 	ip.o mac.o inet_net_ntop.o inet_net_pton.o
  
  all: SUBSYS.o
  
--- 24,30 ----
  	oid.o oracle_compat.o \
  	regexp.o regproc.o ruleutils.o selfuncs.o sets.o \
  	tid.o timestamp.o varchar.o varlena.o version.o \
! 	inet.o mac.o inet_net_ntop.o inet_net_pton.o
  
  all: SUBSYS.o
  
*** src/backend/utils/adt/inet.c.old	Wed Oct  7 10:45:38 1998
--- src/backend/utils/adt/inet.c	Wed Oct  7 10:46:52 1998
***************
*** 19,25 ****
  #include <postgres.h>
  #include <utils/palloc.h>
  #include <utils/builtins.h>
! #include <utils/mac.h>
  
  static int v4bitncmp(unsigned int a1, unsigned int a2, int bits);
  
--- 19,25 ----
  #include <postgres.h>
  #include <utils/palloc.h>
  #include <utils/builtins.h>
! #include <utils/network.h>
  
  static int v4bitncmp(unsigned int a1, unsigned int a2, int bits);
  
*** src/backend/utils/adt/mac.c.old	Wed Oct  7 10:45:43 1998
--- src/backend/utils/adt/mac.c	Wed Oct  7 10:47:11 1998
***************
*** 10,16 ****
  #include <postgres.h>
  #include <utils/palloc.h>
  #include <utils/builtins.h>
! #include <utils/mac.h>
  
  manufacturer manufacturers[] = {
    {0x00, 0x00, 0x0C, "Cisco"},
--- 10,16 ----
  #include <postgres.h>
  #include <utils/palloc.h>
  #include <utils/builtins.h>
! #include <utils/network.h>
  
  manufacturer manufacturers[] = {
    {0x00, 0x00, 0x0C, "Cisco"},
*** src/include/utils/builtins.h.old	Wed Oct  7 10:45:54 1998
--- src/include/utils/builtins.h	Wed Oct  7 10:47:28 1998
***************
*** 28,34 ****
  #include <utils/nabstime.h>
  #include <utils/int8.h>
  #include <utils/cash.h>
! #include <utils/mac.h>
  #include <utils/rel.h>
  
  /*
--- 28,34 ----
  #include <utils/nabstime.h>
  #include <utils/int8.h>
  #include <utils/cash.h>
! #include <utils/network.h>
  #include <utils/rel.h>
  
  /*
***************
*** 518,524 ****
  /* inet_net_pton.c */
  int inet_net_pton(int af, const char *src, void *dst, size_t size);
  
! /* ip.c */
  inet	   *inet_in(char *str);
  char	   *inet_out(inet * addr);
  bool		inet_lt(inet * a1, inet * a2);
--- 518,524 ----
  /* inet_net_pton.c */
  int inet_net_pton(int af, const char *src, void *dst, size_t size);
  
! /* inet.c */
  inet	   *inet_in(char *str);
  char	   *inet_out(inet * addr);
  bool		inet_lt(inet * a1, inet * a2);

[***] Hope that I got it right!  "It works for me."  :-)

-tih
-- 
Popularity is the hallmark of mediocrity.  --Niles Crane, "Frasier"

In response to

Responses

pgsql-hackers by date

Next:From: Horak DanielDate: 1998-10-07 12:03:35
Subject: NT port of PGSQL - success
Previous:From: Tom Ivar HelbekkmoDate: 1998-10-07 09:26:20
Subject: Re: [HACKERS] Open 6.4 items

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group