欢迎来到天天文库
浏览记录
ID:55615462
大小:78.50 KB
页数:3页
时间:2020-05-19
《计算机网络课程设计:(第三章)封装Ethernet帧(完整程序代码).doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、计算机网络课程设计第二章:封装Ethernet帧完整程序:#include#includevoidmain(intargc,char*argv[]){if(argc!=3){cout<<"Pleaseinputcommmand:EncapFrameinput_fileoutput_file"<2、ios::out3、ios::binary4、ios::trunc);for(inti=0;i<7;i++)file.put(char(0xaa)5、);file.put(char(0xab));longpCrcS=file.tellp();chardst_addr[6]={char(0x00),char(0x00),char(0xe4),char(0x86),char(0x3a),char(0xdc)};file.write(dst_addr,sizeof(dst_addr));charsrc_addr[6]={char(0x00),char(0x00),char(0x80),char(0x1a),char(0xe6),char(0x65)};file.write(src_addr,sizeof(src_addr));ifs6、treaminfile;infile.open(argv[1],ios::binary);infile.seekg(0,ios::end);shortlength=(short)infile.tellg();file.put(char(length/256));file.put(char(length%256));char*data=newchar[length];infile.seekg(0,ios::beg);infile.read(data,length);file.write(data,length);infile.close();deletedata;if(length7、<46)for(inti=0;i<46-length;i++)file.put(char(0x00));longpCrc=file.tellp();file.put(char(0x00));shorttotal=short(file.tellp())-(short)pCrcS;file.seekg(pCrcS,ios::beg);unsignedcharcrc=0;while(total--){unsignedchartemp;file.get(temp);for(unsignedchari=(unsignedchar)0x80;i>0;i>>=1){if(crc&0x80){c8、rc<<=1;if(temp&i)crc^=0x01;crc^=0x07;}else{crc<<=1;if(temp&i)crc^=0x01;}}}file.seekp(pCrc,ios::beg);file.put(crc);file.seekg(0,ios::beg);cout<<"Contentofethernetframe:"<9、d";file.close();}结果:
2、ios::out
3、ios::binary
4、ios::trunc);for(inti=0;i<7;i++)file.put(char(0xaa)
5、);file.put(char(0xab));longpCrcS=file.tellp();chardst_addr[6]={char(0x00),char(0x00),char(0xe4),char(0x86),char(0x3a),char(0xdc)};file.write(dst_addr,sizeof(dst_addr));charsrc_addr[6]={char(0x00),char(0x00),char(0x80),char(0x1a),char(0xe6),char(0x65)};file.write(src_addr,sizeof(src_addr));ifs
6、treaminfile;infile.open(argv[1],ios::binary);infile.seekg(0,ios::end);shortlength=(short)infile.tellg();file.put(char(length/256));file.put(char(length%256));char*data=newchar[length];infile.seekg(0,ios::beg);infile.read(data,length);file.write(data,length);infile.close();deletedata;if(length
7、<46)for(inti=0;i<46-length;i++)file.put(char(0x00));longpCrc=file.tellp();file.put(char(0x00));shorttotal=short(file.tellp())-(short)pCrcS;file.seekg(pCrcS,ios::beg);unsignedcharcrc=0;while(total--){unsignedchartemp;file.get(temp);for(unsignedchari=(unsignedchar)0x80;i>0;i>>=1){if(crc&0x80){c
8、rc<<=1;if(temp&i)crc^=0x01;crc^=0x07;}else{crc<<=1;if(temp&i)crc^=0x01;}}}file.seekp(pCrc,ios::beg);file.put(crc);file.seekg(0,ios::beg);cout<<"Contentofethernetframe:"<9、d";file.close();}结果:
9、d";file.close();}结果:
此文档下载收益归作者所有