码迷,mamicode.com
首页 > 系统相关 > 详细

MAC

时间:2014-12-12 17:13:29      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:des   style   ar   sp   for   on   bs   amp   tt   

void HexStrToByte(const char *src, unsigned char *dest, int srcLen)

{

short i;

unsigned char highByte, lowByte;


for (i = 0; i < srcLen; i += 2)

{

highByte = toupper(src[i]);

lowByte  = toupper(src[i + 1]);


if (highByte > 0x39)

highByte -= 0x37;

else

highByte -= 0x30;


if (lowByte > 0x39)

lowByte -= 0x37;

else

lowByte -= 0x30;


dest[i / 2] = (highByte << 4) | lowByte;

}

return;

}




unsigned short calc_crc( unsigned char *ptr, int len)

{

  unsigned short crc1 = 0,da=0,bbb =0;


    while ( len-- != 0 )

    {

        da = ( crc1 >> 8 ) & 0x00ff;    //8??????????CRC??8?

        crc1 <<= 8;                            //?8?,???CRC??8???

        crc1 ^= ccitt_table[ ( da ^ ( *ptr ) )];        // ?8?????????????CRC ,??????CRC

        ptr++;

    }


    return crc1;


int YD_Crc16(char *source,int len,char *mac)

{

        char    dest[1000] = {0};

        int      nret = 0;


HexStrToByte(source, dest,  len);

nret =  calc_crc(dest,len/2);

sprintf(mac,"%04X",nret);

memcpy(&mac[4],"0000",4);

}


MAC

标签:des   style   ar   sp   for   on   bs   amp   tt   

原文地址:http://my.oschina.net/u/2252538/blog/355549

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!