ip最长匹配计算,mysql使用inet_aton函数实现
mask是ip的:
select * from (
select *,(inet_aton('10.181.88.1')&inet_aton(mask))=inet_aton(prefix) as matchs from route_table rt where device_ip ='10.189.255.2'
)t where matchs=1
mask是位数的:
SELECT *
from route_table rt where device_ip ='10.189.255.2'
and INET_ATON('10.189.252.1') & (4294967295 << (32 - mask)) = INET_ATON(prefix) & (4294967295 << (32 - mask))
ORDER BY mask DESC