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 replaced by
> >
> >     nework_addr == (ip_addr & (-1 << network_size))
> >
> > which will be true if the IP address is in the network.
> 
> Is this Java or C?  For C, this breaks if network_size == 32.

  It breaks for everything except network_size == 16.

  You want something closer to (ip_addr & (~(~0 << network_size)))

  Again, that only works for v4.  Part of the beauty of the INET and
  CIDR types in PostgreSQL is that they take both v4 and v6
  addresses/networks and all the operations work on both address types
  automatically.

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"'People who live in bamboo houses should not throw pandas.' Jesus said that."
   - "The Ninja", www.AskANinja.com, "Special Delivery 10: Pop!Tech 2006"
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to