Discussion:
inet_aton
Kevin Waterson
2003-10-13 07:51:30 UTC
Permalink
I am trying to switch my db from mysql and have a start field
of IP addresses and a length field of the length of the IP net.
eg:
start would have a value of 202.1.33.3
length would have a value of 4096

In mysql I would do something like
SELECT * FROM tablename WHERE inet_aton("127.0.0.1") BETWEEN inet_aton(start) AND inet_aton(start)+length

How can I do something similar with sqlite?

Kind regards
Kevin
--
______
(_____ \
_____) ) ____ ____ ____ ____
| ____/ / _ ) / _ | / ___) / _ )
| | ( (/ / ( ( | |( (___ ( (/ /
|_| \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs from home.
Over 14,500 titles. Free Shipping
& No Late Fees. Try Netflix for FREE!
http://us.click.yahoo.com/ArdFIC/hP.FAA/3jkFAA/EbFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
sqlite-unsubscribe-***@public.gmane.org



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Mrs. Brisby
2003-10-13 12:13:46 UTC
Permalink
1. Change your application; Have it treat "start" as a 32-bit (or
larger) integer.

$ cat > test.c
int main() {
printf("%lu\n", (202<<24)|(1<<16)|(33<<8)|3);
printf("%lu\n", ((202<<24)|(1<<16)|(33<<8)|3)+4096);
return 0;
}
$ gcc -o test test.c && ./test
3389071619
3389075715

This demonstrates how inet_aton() works internally, and it isn't
endian-dependent.


2. Add an inet_aton() function to sqlite that converts an IP address
into a 32-bit unsigned long integer; This is nearly trivial, and the
Wiki has documentation on how to do this, as does earlier entries in the
list archive. Again, the above algorithm describes what you want.
Post by Kevin Waterson
I am trying to switch my db from mysql and have a start field
of IP addresses and a length field of the length of the IP net.
start would have a value of 202.1.33.3
length would have a value of 4096
In mysql I would do something like
SELECT * FROM tablename WHERE inet_aton("127.0.0.1") BETWEEN
inet_aton(start) AND inet_aton(start)+length
How can I do something similar with sqlite?
Kind regards
Kevin
--
______
(_____ \
_____) ) ____ ____ ____ ____
| ____/ / _ ) / _ | / ___) / _ )
| | ( (/ / ( ( | |( (___ ( (/ /
|_| \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia
Yahoo! Groups Sponsor
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/EbFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
sqlite-unsubscribe-***@public.gmane.org



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Kevin Waterson
2003-10-13 14:10:27 UTC
Permalink
Post by Mrs. Brisby
1. Change your application; Have it treat "start" as a 32-bit (or
larger) integer.
2. Add an inet_aton() function to sqlite that converts an IP address
into a 32-bit unsigned long integer; This is nearly trivial, and the
Wiki has documentation on how to do this, as does earlier entries in the
list archive. Again, the above algorithm describes what you want.
I decided to use PHPs ip2long() for the purpose and register a function.

register_tick_function('ip2long', TRUE);
$sql= "SELECT cc FROM registry WHERE PHP('ip2long', start) BETWEEN PHP('ip2long',start) AND PHP('ip2long', start)+length";

Thanks for your time
Kind regards
Kevin
--
______
(_____ \
_____) ) ____ ____ ____ ____
| ____/ / _ ) / _ | / ___) / _ )
| | ( (/ / ( ( | |( (___ ( (/ /
|_| \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/EbFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
sqlite-unsubscribe-***@public.gmane.org



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Loading...