static uint32_t
convert_depth_to_bitmask(uint32_t depth_val)
{
uint32_t bitmask = 0;
int i, j;
for (i = depth_val, j = 0; i > 0; i--, j++)
bitmask |= (1 << (31 - j));
return bitmask;
}
static int
mask_to_iparea(uint32_t addr,uint32_t mask_len,uint32_t *start_ip,uint32_t *end_ip)
{
uint32_t ip;
uint32_t shift_bits ;
if(mask_len == 0){
*start_ip = 0x0;
*end_ip = 0xffffffff;
}else{
shift_bits = 32 - mask_len;
*start_ip = addr & (convert_depth_to_bitmask(mask_len));
ip = addr >> shift_bits;
ip++;//找到下一个网段
*end_ip = (ip << shift_bits) - 1;
}
return 0;
}