计算机网络课程设计:(第三章)封装Ethernet帧(完整程序代码)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

计算机网络课程设计第二章:封装Ethernet帧完整程序:#includeiostream.h#includefstream.hvoidmain(intargc,char*argv[]){if(argc!=3){coutPleaseinputcommmand:EncapFrameinput_fileoutput_fileendl;return;}fstreamfile;file.open(argv[2],ios::in|ios::out|ios::binary|ios::trunc);for(inti=0;i7;i++)file.put(char(0xaa));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));ifstreaminfile;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(length46)for(inti=0;i46-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;i0;i=1){if(crc&0x80){crc=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);coutContentofethernetframe:endl;while(!file.eof()){unsignedchartemp;file.get(temp);couthex(short)temp;}coutendlTheargv[2]iscompleted;file.close();}结果:

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功