您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 计算机通信与网络实验
计算机通信与网络实验———实验整合学生姓名:学生学号:学生班级:专业名称:指导老师:完成日期:目录实验1Codingonerrordectectingalgorithms...........................................1实验2:SimulationonPerformanceofDataLinkControl....................14实验3:BuildingaPeer-to-PeerNetworkandsharingresourses...........19实验3网络实用命令与协议分析.........................................................24实验4-1IPandTCPProtocoalAnalysiswithWireShark.......................32实验4-2IPandTCPProtocoalAnalysiswithWireShark....................38实验4-3IPandTCPProtocoalAnalysiswithWireShark....................42实验5DNS,DataEncapsulationandFrameExamination..................501实验1:Codingonerrordectectingalgorithms实验要求1.CyclicredundancycheckUsingthepolynomialsbelowtoencoderandomgenerateddatastream(40-100bits).ShowtheFCS,andencodeddataframe.CRC-4x4+x+1ITUG.704CRC-16x16+x15+x2+1IBMSDLCCRC-32x32+x26+x23+...+x2+x+1ZIP,RAR,IEEE802LAN/FDDI,IEEE1394,PPP-FCSFortheerrorpatterlistedbelow,whattheconclusiondoesthereceiverget?Canthereceiverfindtheerrors?CaseErrorpatternNoerror0000……0000Oneerror1000…..000Twoerrors100….001RandomerrorsRandomerrorpattern2.ParitycheckUsingevenoroddparitycheckonrandomgenerateddatastream(8-20bits).Showencodeddataframe.Fortheerrorpatterlistedbelow,whattheconclusiondoesthereceiverget?Canthereceiverfindtheerrors?CaseErrorpatternNoerror0000……0000Oneerror1000…..000Twoerrors100….001实验环境:操作系统环境:1)操作系统为:win8(64bit)2)编译环境:Vs20122实验结果:欢迎界面:输入需要传输的数据:Crc校验:模拟信道:CaseErrorpatternNoerror0000……0000Oneerror1000…..000Twoerrors100….001Randomerror随机翻转Noerror:Oneerror:Twoerror:Randomerror:奇偶校验:3Evenparity:Noerror:Oneerror:Twoerror:Oddparity:Noerror:Oneerror:Twoerror:4实验代码:#includestdio.h#includestdlib.h#includememory.h#includestring.h#includeconio.h#includetime.h#defineNO_ERROR1#defineONE_ERROR2#defineTWO_ERROR3#defineRANDOM_ERROR4#defineRESULT1#defineCRC0#defineParity0#definecheck1intflag_parity;//判断奇偶校验voidByteToBit(char*out,constchar*in,intbits);voidinput_message(char*message);intxor(char**p,char*d,intlen);char*crc_function(char*str_p,intlen,char*dividend,intlen_d,inttype,char*crc_p);charParity_check(char*message_output,intlength,intmode);voidmain(){intpattern=0;intchannel_way=0;charmessage[8]={NULL};//datathatproducedbychancecharmessage_output[1000]={NULL};charmessage_crc[]={NULL};//transportintlength;//message'slength5/*这是固定了为4为的crc,当这里改变是就可以直接改变crc的长度了*/chardividend[]=10011;charmessage_input[1000]=;/*这里可以更改数值当时16为crc的时候,此时的len_d为15*/intlen_d=5;//被除数长度设置charflag;while(true){fflush(stdin);//任意输入数据printf(pleaseinputthemessage!\n);gets(message);printf(Aneedtosendthismessage:%s\n,message);length=strlen(message);ByteToBit(message_output,message,length*8);for(intk=0;klength*8;k++){printf(%d,message_output[k]);message_input[k]=message_output[k]+48;}pattern=0;channel_way=0;printf(\n);printf(Codingonerrordectectingalgorithms\n);printf(1.Cyclicredundancycheck\n);printf(2.Paritycheck\n);printf(pleasechicepattern:\n);/*选择进入的检错模式*/scanf(%d,&pattern);fflush(stdin);//清空缓存区if(pattern==1){printf(*************************************\n);printf(analogchannel\n);printf(pleasechoicethewayoferror\n);printf(****1.Noerror*****\n);printf(****2.Oneerror*****\n);printf(****3.Twoerrors*****\n);printf(****4.Randomerrors*****\n);scanf(%d,&channel_way);printf(\ncrc:);//进行crc检测intlen=length*8;//printf(%d\n,len);char*crc=NULL;crc=crc_function(message_input,len,dividend,len_d,CRC,NULL);6for(inti=0;ilen_d;i++){printf(%c,*crc);message_input[length*8+i]=*crc;crc+=1;}printf(\n);/*模拟信道CaseErrorpatternNoerror0000……0000Oneerror1000…..000Twoerrors100….001RandomerrorsRandomerrorpattern*/if(channel_way==NO_ERROR){char*result=NULL;intflagg=0;printf(信道中传输数据:);for(intf=0;flength*8+len_d-1;f++)printf(%c,message_input[f]);printf(\n);printf(正在检错中.......\n);printf(检错结果:);fflush(stdin);result=crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(inti=0;ilen_d-1;i++){printf(%c,*result);if((*result)-48!=0){printf(\nerror!\n);flagg=1;break;}result+=1;}if(flagg==0)printf(\nnoerror!\n);}if(channel_way==ONE_ERROR){char*result=NULL;message_input[0]=((message_input[0]-48)^('1'-48))+48;7printf(信道中传输数据:);for(intf=0;flength*8+len_d-1;f++)printf(%c,message_input[f]);printf(\n);printf(正在检错中.......);printf(检错结果:);result=crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(inti=0;ilen_d-1;i++){if(*result=='1'){printf(dataerror!\n);break;}else{continue;result+=1;}}}if(channel_way==TWO_ERROR){char*result=NULL;message_input[0]=((message_input[0]-48)^('1'-48))+48;message_input[length*8-1]=((message_input[length*8-1]-48)^('1'-48))+48;printf(信道中传输数据:);for(intf=0;flength*8+len_d-1;f++)printf(%c,message_input[f]);printf(\n);printf(正在检错中.......);printf(检错结果:);result=crc_function(message_input,len,dividend,len_d,RESULT,crc);for(inti=0;ilen_d-1;i++){if(*result!='0'){printf(dataerror!\n);break;}else{continue;result+=1;8}}}if(channel_way==RANDOM_ERROR){char*result=NULL;intno;srand((unsigned)time(NULL));//初始化随机数no=rand()%length*8;message_input[no]=((message_input[0]-48)^('1'-48))+48;printf(信道中传输数据:);for(intf=0;flength*8+len_d-1;f
本文标题:计算机通信与网络实验
链接地址:https://www.777doc.com/doc-5706395 .html