MAC范围比较

int checkmac(char *startmac, char *endmac, char *inmac)
{
int i = 0;
int len = 0;
int bigger_than_start = 0;
char *p;
unsigned char start_MAC[6];
unsigned char end_MAC[6];
unsigned char in_MAC[6];
char tmpmac[32]={0};


if (strlen(startmac) != strlen(endmac))
return 0;
len = strlen(startmac);


if (len != strlen(inmac))
return 0;


memcpy(tmpmac,inmac,strlen(inmac));
    if (sscanf (startmac, "%2x:%2x:%2x:%2x:%2x:%2x",
&start_MAC[0], &start_MAC[1], &start_MAC[2], &start_MAC[3], &start_MAC[4], &start_MAC[5]) != 6)
    {
return 0;
    }
    if (sscanf (endmac, "%2x:%2x:%2x:%2x:%2x:%2x",
&end_MAC[0], &end_MAC[1], &end_MAC[2], &end_MAC[3], &end_MAC[4], &end_MAC[5]) != 6)
    {
return 0;
    }
    if (sscanf (tmpmac, "%2x:%2x:%2x:%2x:%2x:%2x",
&in_MAC[0], &in_MAC[1], &in_MAC[2], &in_MAC[3], &in_MAC[4], &in_MAC[5]) != 6)
    {
return 0;
    }
    for(i=0;i<6;i++)
    {
        printf("%2x %2x %2x\n", start_MAC[i], in_MAC[i], end_MAC[i]);
    }
    for(i=0 ;i<3; i++)
    {
        if(start_MAC[i]!=end_MAC[i] || start_MAC[i]!=in_MAC[i])
            return 0;
    }


    if(start_MAC[3]<=in_MAC[3] && end_MAC[3]>in_MAC[3])
    { 
       return 1;
    }
    else
    {
        if(end_MAC[3]!= in_MAC[3])
             return 0;
    }
    if(start_MAC[4]<=in_MAC[4] && end_MAC[4]>in_MAC[4])
    { 
       return 1;
    }
    else
    {
        if(end_MAC[4]!= in_MAC[4])
             return 0;
    }


    if(start_MAC[5]<=in_MAC[5] && end_MAC[5]>in_MAC[5])
    { 
       return 1;
    }
    else if(end_MAC[5]== in_MAC[5])
    {
        return 1;
    }
    else
    {
        return 0;
    }
    
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值