c语言mac协议实现,C语言实现MAC帧的封装与解封装

/*

目标:

封装

1.将inputFile文件中的数据封装成MAC帧,封装好的MAC帧写入outputFile文件中.

2.如果数据长度小于46字节,则补全到46字节

3.如果数据长度大于1500,则封装成多个MAC帧

解封装:

读取outputFile中的数据,并逐个显示帧的信息

其实我们要求还是蛮低的,上面有好多是自己添加的

*/

#include 

#include 

#define MAXSIZE 1500

#define echo(format,str) printf("%"#format,str)

#define inputFile "inputFile.txt"

#define outputFile "outputFile.txt"

void flush()

{

fflush(stdin);

fflush(stdout);

}

unsigned int  crc8(unsigned char *ptr,unsigned  int len)

/*

CRC校验,ptr是需要计算的数组首地址,len是需要计算的长度

*/

{

unsigned int  CRC = 0;

unsigned int  i;

while(len--){

CRC = CRC^ *ptr++;

for(i = 0; i 

if(CRC & 0x01){

CRC = (CRC >> 1 )^ 0x8c;

}

else{

CRC >>= 1;

}

}

}

return CRC;

}

int encapsulation()

/*帧封装函数*/

{

int i,dataCrc,nu,j,lastNu,sum;

FILE *fpIn,*fpOut;

int src[6],des[6];

char type[2],data[MAXSIZE];

if((fpIn=fopen(inputFile,"a+"))==NULL)

{

echo(s,"打开文件失败!");<

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值