《視頻處理與傳輸》實驗報告材料_第1頁
《視頻處理與傳輸》實驗報告材料_第2頁
《視頻處理與傳輸》實驗報告材料_第3頁
《視頻處理與傳輸》實驗報告材料_第4頁
《視頻處理與傳輸》實驗報告材料_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

?視頻辦理與傳輸?實驗報告資料?視頻辦理與傳輸?實驗報告資料?視頻辦理與傳輸?實驗報告資料適用標準文案西南科技大學?視頻辦理與傳輸?實驗報告題目:實驗三設計者:專業(yè)班級:學號:指導教師:2021年12月23日優(yōu)異文檔適用標準文案一、實驗目的1.認識和認識TCP的有關內容;2.學習和掌握TCP模塊的C語言編程;3.試一試用C語言寫出TCP有限狀態(tài)機的實現(xiàn)函數(shù)二、實驗內容TCP〔TransmissionControlProtocol傳輸控制協(xié)議〕是一種面向連結〔連接導向〕的、靠譜的、鑒于IP的傳輸層協(xié)議,由IETF的RFC793說明〔specified〕。TCP在IP報文的協(xié)議號是6。設計一個C程序實現(xiàn)TCP。三、實驗過程1、創(chuàng)辦一頭文件,包含C語言實現(xiàn)TCP的全部常量。2、達成struct語句,它是TCP首部的說明語句。3、達成struct語句,它是TCP報文的說明語句。4、用C語言寫出TCP有限狀態(tài)機的函數(shù)。四、實驗結果及分析1、頭文件#ifndef_TCP_H#define_TCP_H#include<stdio.h>#include<stdlib.h>#include<errno.h>#include<string.h>#include<sys/types.h>#include<netinet/in.h>#include<sys/socket.h>#include<sys/wait.h>#defineSERVERPORT3333/*效力器監(jiān)聽端口號*/#defineBACKLOG10/*最大同時連結懇求數(shù)*/#endif優(yōu)異文檔適用標準文案2、TCP首部:structTCP_Header{u_charbyte1;u_charbyte2;u_charbyte3;u_charbyte4;}ip_address;/*IPv4首部*/structTCP_header{unsignedshortSPortAddru_charver_ihl;//版本(4bits)+首部長度(4bits)==8u_chartos;//效力種類(Typeofservice)u_shorttlen;//總長(Totallength)u_shortidentification;//表記(Identification)u_shortflags_fo;//標記位(Flags)(3bits)+段偏移量(Fragmentoffset)(13bits)u_charttl;//存活時間(Timetolive)u_charproto;//協(xié)議(Protocol)u_shortcrc;//首部校驗和(Headerchecksum)ip_addresssaddr;//源地點(Sourceaddress)ip_addressdaddr;//目的地點(Destinationaddress)u_intop_pad;//選項與填補(Option+Padding)}ip_header;3、structTCPPacket{structTCP_HeadertcpHeader;uint16source;/*Sourceport*/uint16dest;/*Destinationport*/int32seq;/*Sequencenumber*/int32ack;/*Acknowledgmentnumber*/uint16wnd;/*Receiverflowcontrolwindow*/uint16checksum;/*Checksum*/uint16up;/*Urgentpointer*/uint16mss;/*Optionalmaxsegsize*/uint8wsopt;/*Optionalwindowscalefactor*/優(yōu)異文檔適用標準文案uint32tsval;/*Outboundtimestamp*/uint32tsecr;/*Timestampechofield*/struct{unsignedintcongest:1;/*EchoedIPcongestionexperiencedbit*/unsignedinturg:1;unsignedintack:1;unsignedintpsh:1;unsignedintrst:1;unsignedintsyn:1;unsignedintfin:1;unsignedintmss:1;/*MSSoptionpresent*/unsignedintwscale:1;/*Windowscaleoptionpresent*/unsignedinttstamp:1;/*Timestampoptionpresent*/tcpData;}};4、TCP有限狀態(tài)機#include"global.h"#include"timer.h"#include"mbuf.h"#include"netuser.h"#include"internet.h"#include"tcp.h"#include"ip.h"voidtcp_output(tcb)registerstructtcb*tcb;{structmbuf*dbp;/*Headeranddatabufferpointers*/structtcpseg;/*Localworkingcopyofheader*/uint16ssize;/*Sizeofcurrentsegmentbeingsent,*includingSYNandFINflags*/uint16dsize;/*SizeofsegmentlessSYNandFIN*/int32usable;/*Usablewindow*/int32sent;/*Sequencecount(inclSYN/FIN)already*inthepipebutnotyetacked*/優(yōu)異文檔適用標準文案int32rto;/*Retransmittimeoutsetting*/if(tcb==NULL)return;switch(tcb->state){caseTCP_LISTEN:caseTCP_CLOSED:return;/*Don'tsendanything*/}for(;;){memset(&seg,0,sizeof(seg));/*Computedataalreadyinflight*/sent=tcb->snd.ptr-tcb->snd.una;usable=min(tcb->snd.wnd,tcb->cwind);if(usable>sent)usable-=sent;/*Mostcommoncase*/elseif(usable==0&&sent==0)usable=1;/*Closedwindowprobe*/elseusable=0;/*Windowclosedorshrunken*/ssize=min(tcb->sndcnt-sent,usable);ssize=min(ssize,tcb->mss);&&sent!=0&&ssize<tcb->mss&&!(tcb->state==TCP_FINWAIT1&&ssize==tcb->sndcnt-sent)){ssize=0;}if(!tcb->flags.synack&&!Tcp_syndata){if(tcb->snd.ptr==tcb->iss)ssize=min(1,ssize);/*SendonlySYN*/elsessize=0;/*Don'tsendanything*/}if(tcb->flags.force&&tcb->snd.ptr!=tcb->snd.nxt)ssize=0;if(ssize==0&&!tcb->flags.force)break;/*Noneedtosendanything*/tcb->flags.force=0;/*Onlyoneforcedsegment!*/seg.source=tcb->conn.local.port;seg.dest=tcb->conn.remote.port;=1;/*EverystateexceptTCP_SYN_SENT*/seg.flags.congest=tcb->flags.congest;優(yōu)異文檔適用標準文案if(tcb->state==TCP_SYN_SENT)seg.flags.ack=0;/*Haven'tseenanythingyet*/dsize=ssize;if(!tcb->flags.synack&&tcb->snd.ptr==tcb->iss){/*SendSYN*/seg.flags.syn=1;dsize--;/*SYNisn'treallyinsndqueue*//*AlsosendMSS,wscaleandtstamp(ifOK)*/seg.mss=Tcp_mss;seg.flags.mss=1;seg.wsopt=DEF_WSCALE;seg.flags.wscale=1;if(Tcp_tstamps){seg.flags.tstamp=1;seg.tsval=msclock();}}if(ssize==0)seg.seq=tcb->snd.nxt;elseseg.seq=tcb->snd.ptr;tcb->last_ack_sent=seg.ack=tcb->rcv.nxt;if(seg.flags.syn||!tcb->flags.ws_ok)seg.wnd=tcb->rcv.wnd;elseseg.wnd=tcb->rcv.wnd>>tcb->rcv.wind_scale;dbp=ambufw(TCP_HDR_PAD+dsize);dbp->data+=TCP_HDR_PAD;/*Allowroomforotherhdrs*/If(dsize!=0){int32offset;offset=sent;if(!tcb->flags.synack&&sent!=0)offset--;dbp->cnt=extract(tcb->sndq,(uint16)offset,dbp->data,dsize);if(dbp->cnt!=dsize){/*Weranpasttheendofthesendqueue;*sendaFIN*/seg.flags.fin=1;dsize--;}}if(dsize!=0&&sent+ssize==tcb->sndcnt)優(yōu)異文檔適用標準文案seg.flags.psh=1;if(tcb->snd.ptr<tcb->snd.nxt)tcb->resent+=-tcb->snd.ptr,ssize);tcb->snd.ptr+=ssize;if(seq_gt(tcb->snd.ptr,tcb->snd.nxt))tcb->snd.nxt=tcb->snd.ptr;if(tcb->flags.ts_ok&&seg.flags.ack){seg.flags.tstamp=1;seg.tsval=msclock();seg.tsecr=tcb->ts_recent;}/*GenerateTCPheader,computechecksum,andlinkindata*/htontcp(&seg,&dbp,tcb->conn.local.address,tcb->conn.remote.address)if(ssize!=0){/*Setroundtriptimer.*/rto=backoff(tcb->backoff)*(4*tcb->mdev+tcb->srtt);set_timer(&tcb->timer,max(MIN_RTO,rto));if(!run_timer(&tcb->timer))start_timer(&tcb->timer);/*Ifroundtriptimerisn'trunning,startit*/if(tcb->flags.ts_ok||!tcb->flags.rtt_run){tcb->flags.rtt_run=1;tcb->rtt_time=msclock();tcb->rttseq=tcb->snd.ptr;tcb->rttack=tcb->snd.una;}}if(tcb->flags.retran)tcpRetransSegs++;elsetcpOutSegs++;ip_send(tcb->conn.local.address,tcb->conn.remote.address,TCP_PTCL,tcb->tos,0,&dbp,len_p(

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論