Re: [sqlite] cidr data type

2008-04-21 Thread Florian Weimer
* Jay A. Kreibich: > Yeah, I screwed that up. I was too caught up on the other error. > > In the original function (-1 << network_size) returns the wrong bit > mask. For example, 10.0.0.0/8 should return a netmask of 255.0.0.0, > or 0xFF00. The original function will return

Re: [sqlite] cidr data type

2008-04-20 Thread Jay A. Kreibich
On Sun, Apr 20, 2008 at 09:29:34AM -0600, Dennis Cote scratched on the wall: > Jay A. Kreibich wrote: > > > > It breaks for everything except network_size == 16. > > > Why do you say that? > > You want something closer to (ip_addr & (~(~0 << network_size))) > > > In SQLite ~0 is -1. > >

Re: [sqlite] cidr data type

2008-04-20 Thread Florian Weimer
* Jay A. Kreibich: >> Is this Java or C? For C, this breaks if network_size == 32. > > It breaks for everything except network_size == 16. I was alluding to the fact that a popular architecture implements modulo-32 shifts for 32-bit integers (and modulo-64 shifts for 64-bit integers), for

Re: [sqlite] cidr data type

2008-04-20 Thread Dennis Cote
Jay A. Kreibich wrote: > > It breaks for everything except network_size == 16. > Why do you say that? > You want something closer to (ip_addr & (~(~0 << network_size))) > In SQLite ~0 is -1. sqlite> select ~0; -1 So your inner expression is only a more complicated way of saying

Re: [sqlite] cidr data type

2008-04-20 Thread Dennis Cote
Florian Weimer wrote: > > Is this Java or C? For C, this breaks if network_size == 32. > It is SQL (with SQLite extensions which are modeled after C). SQLite has a 64 bit integer type so the bit shifting works as expected for all values up to 63. The same logic can be used in other

Re: [sqlite] cidr data type

2008-04-20 Thread John Stanton
Jay A. Kreibich wrote: > On Sun, Apr 20, 2008 at 11:13:56AM +0200, Florian Weimer scratched on the > wall: > >>* Dennis Cote: >> >> >>>This last function can be implemented using bit manipulation operators >>>in SQL or in a custom function in C. >>> >>>containedIn(ip_addr, network_addr,

Re: [sqlite] cidr data type

2008-04-20 Thread Jay A. Kreibich
On Sun, Apr 20, 2008 at 11:13:56AM +0200, Florian Weimer scratched on the wall: > * Dennis Cote: > > > This last function can be implemented using bit manipulation operators > > in SQL or in a custom function in C. > > > > containedIn(ip_addr, network_addr, network_size) > > > > can be

Re: [sqlite] cidr data type

2008-04-20 Thread Florian Weimer
* Dennis Cote: > This last function can be implemented using bit manipulation operators > in SQL or in a custom function in C. > > containedIn(ip_addr, network_addr, network_size) > > can be replaced by > > nework_addr == (ip_addr & (-1 << network_size)) > > which will be true if the IP

Re: [sqlite] cidr data type

2008-04-20 Thread John Stanton
What stops you from building in the 128 bit address logic? Christof Meerwald wrote: > On Fri, 18 Apr 2008 15:59:14 -0600, Dennis Cote wrote: > >>Christof Meerwald wrote: >> >>>Currently, I am thinking of storing start and end IP addresses as a blob in >>>the database - that way I would be able

Re: [sqlite] cidr data type

2008-04-19 Thread Nicolas Williams
On Fri, Apr 18, 2008 at 08:59:17PM -0500, John Stanton wrote: > Use a function and convert the IP address from dotted format to a 32 bit > unsigned integer. You can AND and OR these to establish inclusion and > exclusion. That doesn't get you the prefix length. If you represent the

Re: [sqlite] cidr data type

2008-04-19 Thread Christof Meerwald
On Fri, 18 Apr 2008 15:59:14 -0600, Dennis Cote wrote: > Christof Meerwald wrote: >> Currently, I am thinking of storing start and end IP addresses as a blob in >> the database - that way I would be able to use the "between" operator in >> selects, e.g. >> select X'c0a81234' between X'c0a8'

Re: [sqlite] cidr data type

2008-04-18 Thread John Stanton
Christof Meerwald wrote: > Hi, > > does SQLite have anything similar to PostgreSQL's cidr data type (see > http://www.postgresql.org/docs/8.3/interactive/datatype-net-types.html). > > I would be particularly interested in being able to use a "contained in" > operator in selects - in PostgreSQL

Re: [sqlite] cidr data type

2008-04-18 Thread Nicolas Williams
On Fri, Apr 18, 2008 at 04:34:07PM -0500, Nicolas Williams wrote: > You could have functions to convert to/from display notation, and then > the internal storage format could be an integer, or even as a bit string ^^^ Here I had in mind a 64-bit

Re: [sqlite] cidr data type

2008-04-18 Thread Nicolas Williams
On Fri, Apr 18, 2008 at 11:08:24PM +0200, Christof Meerwald wrote: > does SQLite have anything similar to PostgreSQL's cidr data type (see > http://www.postgresql.org/docs/8.3/interactive/datatype-net-types.html). No. > Currently, I am thinking of storing start and end IP addresses as a blob in

[sqlite] cidr data type

2008-04-18 Thread Christof Meerwald
Hi, does SQLite have anything similar to PostgreSQL's cidr data type (see http://www.postgresql.org/docs/8.3/interactive/datatype-net-types.html). I would be particularly interested in being able to use a "contained in" operator in selects - in PostgreSQL you are able to do: select inet