MySQL IP address in subnet

DELIMITER |
DROP FUNCTION IF EXISTS `isIPInsubnet`|
CREATE FUNCTION isIPInsubnet( ip CHAR(32), subnet CHAR(32) ) RETURNS INT
begin
set @subnet_min = INET_ATON(LEFT(subnet, INSTR(subnet, '/')-1));
set @subnet_max = INET_ATON(LEFT(subnet, INSTR(subnet, '/')-1))+POW(2, 32-SUBSTRING(subnet, INSTR(subnet, '/')+1))-1;
if (INET_ATON(ip) > @subnet_min and INET_ATON(ip) < @subnet_max) then
return 1;
else
return 0;
end if;
end|
DELIMITER ;

Thanks to Bill Karwin!