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

Re: [HACKERS] CIDR type and functions

From: darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain)
To: maillist(at)candle(dot)pha(dot)pa(dot)us (Bruce Momjian)
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] CIDR type and functions
Date: 1998-10-09 21:51:41
Message-ID: m0zRkRp-0000exC@druid.net (view raw or flat)
Thread:
Lists: pgsql-hackers
Thus spake Bruce Momjian
> > Here are the functions I had suggested.
> > 
> >     netmask('192.3.4.5/24::cidr') == 255.255.255.0
> >     masklen('192.3.4.5/24::cidr') == 24
> >     host('192.3.4.5/24::cidr') == 192.3.4.5
> >     network('192.3.4.5/24::cidr') == 192.3.4.0

I forgot
        broadcast('192.3.4.5/24::cidr') == 192.3.4.255

> > and perhaps;
> > 
> >     class('192.3.4.5/24::cidr') == C
> >     classnet('192.3.4.5/24::cidr') == 192.3.4

I'll leave these for the moment as I'm not sure what to do with invalid
classful addresses such as 192.3.4.5/16.  I'll bring it up again after
6.4 is released.

> > Can I help code up some of this stuff?
> 
> Yes, we need those.  Code them up, and I will add them as standard
> types.

OK, I started but I could use a small change to inet_net_ntop.c which
I think impliments something we discussed anyway.  I just need to know
if this is going to affect anything else.  Basically it allows for
the number of bits to be -1 which is interpreted as a host with
unspecified netmask.  The changes cause all outputs to leave of
the netmask part if it is -1.  I realize that I will have to change
some of the other functions in inet.c but is there anything else
that might bite me?

If there is no problem I'll resubmit this to the patches list.

*** ../src.original/./backend/utils/adt/inet_net_ntop.c	Fri Oct  9 17:37:27 1998
--- ./backend/utils/adt/inet_net_ntop.c	Fri Oct  9 17:39:05 1998
***************
*** 85,90 ****
--- 85,97 ----
  	char	   *t;
  	u_int		m;
  	int			b;
+ 	int			print_bits = 1;
+ 
+ 	if (bits == -1)
+ 	{
+ 		bits = 32;
+ 		print_bits = 0;
+ 	}
  
  	if (bits < 0 || bits > 32)
  	{
***************
*** 129,137 ****
  	}
  
  	/* Format CIDR /width. */
! 	if (size < sizeof "/32")
! 		goto emsgsize;
! 	dst += SPRINTF((dst, "/%u", bits));
  	return (odst);
  
  emsgsize:
--- 136,147 ----
  	}
  
  	/* Format CIDR /width. */
! 	if (print_bits)
! 	{
! 		if (size < sizeof "/32")
! 			goto emsgsize;
! 		dst += SPRINTF((dst, "/%u", bits));
! 	}
  	return (odst);
  
  emsgsize:


-- 
D'Arcy J.M. Cain <darcy(at){druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.

In response to

Responses

pgsql-hackers by date

Next:From: Bruce MomjianDate: 1998-10-09 21:58:31
Subject: Re: [HACKERS] PL compile warning messages
Previous:From: Bruce MomjianDate: 1998-10-09 21:41:18
Subject: Re: [HACKERS] dynamic libraries

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