最近要用到mac地址的动态计算,网上苦找无果,只好自己动手写写。有待修正!
int macDec(unsigned char *mac1,unsigned char *mac2,unsigned char *mac3,int w)
{
int i=0,j=0,k=0;
char mac;
int total = 0;
mac3[w-i]=mac2[w-i]-mac1[w-i];
if(mac2[w-i] {
j=w-i;
mac2[j-1]-=0x01;
mac3[w-i]=0x100+mac2[w-i]-mac1[w-i];
rpt:
if(mac2[j-1]==0x0)
{
mac2[j-1]-=0x01;
if(j>0)
{
j--;
goto rpt;
}
}
}
if(w--> 0)
{
macDec(mac1,mac2,mac3,w);
}
if(w == 0)
{
for(k=0;k<6;k++)
{
total+=mac3[k]*pow(16,(5-k)*2);
}
return total;
}
}
阅读(1298) | 评论(0) | 转发(0) |