[exim] CIDR and MySQL

Top Page
Delete this message
Reply to this message
Author: Wakko Warner
Date:  
To: exim-users
Subject: [exim] CIDR and MySQL
I noticed a couple months ago that someone wanted to know how to use CIDR
notation with mysql.

I came up with a nasty way of doing this.

The following fragment can be used as a conditional expression.
((substring_index(@a,'.',1)<<24)|(substring_index(substring_index(@a,'.',2),'.',-1)<<16)|(substring_index(substring_index(@a,'.',-2),'.',1)<<8)|substring_index(@a,'.',-1))&(~(4294967295>>substring_index(@t,'/',-1))&4294967295)=((substring_index(@t,'.',1)<<24)|(substring_index(substring_index(@t,'.',2),'.',-1)<<16)|(substring_index(substring_index(@t,'.',-2),'.',1)<<8)|substring_index(substring_index(@t,'.',-1),'/',1))

@a is the address you're testing, @t is the test (CIDR).

It's long, it's ugly, it works; but it does not support @t in anything other
than aaa.bbb.ccc.ddd/mm format. It probably would be better if it was a
stored function. (I don't have mysql 5.0 or higher installed yet =)

--
Lab tests show that use of micro$oft causes cancer in lab animals
Got Gas???