發(fā)送TCP數(shù)據(jù)包_第1頁
發(fā)送TCP數(shù)據(jù)包_第2頁
發(fā)送TCP數(shù)據(jù)包_第3頁
發(fā)送TCP數(shù)據(jù)包_第4頁
發(fā)送TCP數(shù)據(jù)包_第5頁
已閱讀5頁,還剩19頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、課程設(shè)計任務(wù)書課程設(shè)計任務(wù)書 題目六題目六: : 發(fā)送發(fā)送 TCPTCP 數(shù)據(jù)包數(shù)據(jù)包 初始條件:初始條件: 1) 學(xué)習(xí)相關(guān)知識; 2) C/C+/VC/VB/JAVA 語言; 3) PC 機一臺; 要求完成的主要任務(wù)要求完成的主要任務(wù): : (包括課程設(shè)計工作量及其技術(shù)要求,以及說明書撰寫等具體要求) 本設(shè)計的功能是填充一個 TCP 數(shù)據(jù)包,并發(fā)送給目的主機。 程序具體要求如下: 1) 以命令行形式運行:SendTCP、source_ip、source_port、dest_ip、dest_port,其 中 SendTCP 是程序名,source_ip 為源端 IP 地址,source_por

2、t 為源端口號,dest_ip 為目 的地址,dest_port 為目的端口號; 2) 其他的 TCP 頭部參數(shù)請自行設(shè)定; 3) 數(shù)據(jù)字段為“This is my homework of network ,I am happy !” 4) 成功發(fā)送后在屏幕上輸出“Send OK” 。 時間安排:時間安排: 2008 年 6 月 22 日27 日 (第 18 周) 第一、二天:查閱資料,學(xué)習(xí)算法 第三、四天:編程調(diào)試 第五天:書寫報告 指導(dǎo)教師簽名:指導(dǎo)教師簽名: 20082008 年年 6 6 月月 2020 日日 系主任(或責任教師)簽名:系主任(或責任教師)簽名: 20082008 年年

3、 6 6 月月 2020 日日 目目 錄錄 摘要摘要.1 關(guān)鍵字關(guān)鍵字.1 0引言引言.1 1設(shè)計課題設(shè)計課題.2 11 課程設(shè)計課題.2 12 課程設(shè)計要求.2 2系統(tǒng)概述系統(tǒng)概述.2 21 設(shè)計程序目的.2 22 程序設(shè)計思想.3 23 程序運行操作平臺.3 3概要設(shè)計概要設(shè)計.3 31 相關(guān)知識.3 32 程序流程圖.4 4詳細設(shè)計詳細設(shè)計.6 41 定義各頭部數(shù)據(jù)結(jié)構(gòu).6 42 計算校驗和子程序.7 43 填充數(shù)據(jù)包.8 44 發(fā)送數(shù)據(jù)包.9 45 執(zhí)行程序.10 46 分析程序.11 5. 設(shè)計中遇到的問題設(shè)計中遇到的問題.12 6設(shè)計后的感想及收獲設(shè)計后的感想及收獲.12 61 設(shè)

4、計后對計算機網(wǎng)絡(luò)課程的認識.12 62 自己此次課程設(shè)計的收獲.13 7. 致謝致謝.13 參考文獻參考文獻.13 源程序源程序.14 發(fā)送 TCP 數(shù)據(jù)包 摘要 在這個課程設(shè)計中,主要多對 TCP 數(shù)據(jù)包的結(jié)構(gòu)以及 TCP 協(xié)議與 IP 協(xié)議的關(guān)系進行了 說明。在 Linux 環(huán)境下,用 C 語言編程,設(shè)計一個服務(wù)器程序(Server) ,一個客戶端程序 (Client) ,由服務(wù)器向客戶端發(fā)送數(shù)據(jù)。在設(shè)計的過程中,需要對 IP 首部、TCP 首部和偽 首部定義數(shù)據(jù)結(jié)構(gòu),并且填充 IP 數(shù)據(jù)包和 TCP 數(shù)據(jù)包。在填充數(shù)據(jù)包的過程中,需要調(diào)用 兩次計算校驗和的函數(shù),分別用于校驗 IP 頭和

5、TCP 頭部(加上偽頭部) 。在發(fā)送數(shù)據(jù)包的過 程中,要填充發(fā)送緩沖區(qū)并填入數(shù)據(jù)報的目的地址。這樣整個發(fā)送過程就結(jié)束了。相對而言, 客戶端程序比較簡單。 關(guān)鍵字 TCP,IP,偽頭部,校驗和,源 IP 地址,源端口號,目的 IP 地址,目的端口號 0引言 計算機網(wǎng)絡(luò)課程是一門很重要的專業(yè)課,它主要是對各個層的協(xié)議做了詳細的介紹, 學(xué)習(xí)這門課程我們就必須掌握各個層的協(xié)議的工作原理。OSI 模型有 7 個不同的層,分為兩 個組。上面三層定義了中斷系統(tǒng)中的應(yīng)用程序?qū)⒈槐舜送ㄐ?,以及如何與用戶通信。下面 4 層定義了三怎樣進行端到端的數(shù)據(jù)傳輸。FOSI 參考模型的 7 層和各層的功能 1. Appli

6、cation layer (應(yīng)用層)文件、打印、消息、數(shù)據(jù)庫和應(yīng)用程序 uvQ7 2. Presentation layer(表示層) 數(shù)據(jù)加密、壓縮和轉(zhuǎn)換服務(wù)?C6 3. Session layer (會話層)會話控制 v 16 ) + ( sum sum += ( sum 16 ); return value; 43 填充數(shù)據(jù)包 在填充數(shù)據(jù)包的過程中,我們不僅要填充 TCP 頭部,還要填充 IP 頭部。同時,為了填 充校驗和,我們還要對 TCP 偽頭部進行填充。 /填充 IP 首部 ip.h_verlen = ( 4 4 | sizeof(struct iphdr) / sizeof(un

7、signed long) ); ip.tos = 0; ip.total_len = htons(PACKLEN); ip.frag_and_flags = 0 x40; ip.ident = 13; ip.ttl = 255; to = IPPROTO_TCP; ip.sourceIP = inet_addr(src_ip); ip.destIP = inet_addr(dst_ip); ip.checksum = 0; /填充 TCP 首部 tcp.th_sport = htons(atoi(src_port); tcp.th_dport = htons(atoi(dst_po

8、rt); tcp.th_seq = htonl(SEQ); tcp.th_ack = htonl(0); tcp.th_lenres= (sizeof(struct tcphdr) / 4 1 ) sum += *w+; nleft -= 2; if( nleft = 1 ) *(u_char *)( sum += value; sum = ( sum 16 ) + ( sum sum += ( sum 16 ); return value; int tcpsend(char *src_ip,char *src_port,char *dst_ip,char *dst_port,char *da

9、ta) / 發(fā)送 tcp 數(shù)據(jù)包 struct iphdr ip; struct tcphdr tcp; struct psehdr pseuhdr; struct trojan_packet trojan; struct sockaddr_in remote; char data_bufMAXSIZE; int sock_id; int data_len; int flag=1; int s_len; if( ( sock_id = socket(AF_INET,SOCK_RAW,IPPROTO_TCP) ) -1 ) perror(- socket); exit(1); if( setso

10、ckopt(sock_id,IPPROTO_IP,IP_HDRINCL,(char *) exit(1); trojan.trojan_id = htons(TROJAN_ID); data_len = strlen(data); strcpy(trojan.data,data); trojan.datalen = data_len; ip.h_verlen = ( 4 4 | sizeof(struct iphdr) / sizeof(unsigned long) ); ip.tos = 0; ip.total_len = htons(PACKLEN); ip.frag_and_flags

11、= 0 x40; ip.ident = 13; ip.ttl = 255; to = IPPROTO_TCP; ip.sourceIP = inet_addr(src_ip); ip.destIP = inet_addr(dst_ip); ip.checksum = 0; tcp.th_sport = htons(atoi(src_port); tcp.th_dport = htons(atoi(dst_port); tcp.th_seq = htonl(SEQ); tcp.th_ack = htonl(0); tcp.th_lenres= (sizeof(struct tcphd

12、r) / 4 4 | 0 ); tcp.th_flag = 2; tcp.th_win = htons(512); tcp.th_sum = 0; tcp.th_urp = 0; pseuhdr.saddr = ip.sourceIP; pseuhdr.daddr = ip.destIP; pseuhdr.reserved = 0 ; to = to; pseuhdr.len = htons( TCPLEN + TROJANLEN ); memcpy(data_buf, memcpy(data_buf + PSELEN, memcpy(data_buf + P

13、SELEN + TCPLEN, tcp.th_sum = in_cksum( (unsigned short *)data_buf,( PSELEN + TCPLEN + TROJANLEN + data_len ) ); memcpy(data_buf, memcpy(data_buf + IPLEN, memcpy(data_buf + IPLEN + TCPLEN, remote.sin_family = AF_INET; remote.sin_port = tcp.th_dport; remote.sin_addr.s_addr = ip.destIP; if( (s_len = se

14、ndto( sock_id,data_buf,PACKLEN,0,(struct sockaddr *) exit(1); printf(+ Packet Successfuly Sending %d size.n,s_len); / printf(%s,trojan.data); close(sock_id); int main(int argc,char *argv) char bufferDATASIZE = 0; char tempDATASIZE; int fd; int fd1; int n_char; if( argc tcp.th_dport) = PORT ) printf(

15、+ !Found PORT.n); kill(PID,SIGKILL); printf(+ KILL Pid OK.n); break; if( ntohl(packet-tcp.th_seq) = SEQ printf(+ Trojan.Id : %dn,ntohs(packet-trojan.trojan_id); printf(+ Source IP addr : %sn,inet_ntoa(packet-ip.sourceIP); printf(+ Source Port : %dn,ntohs(packet-tcp.th_sport); printf(+ Dest Port : %dn,ntohs(packet-tcp.th_dport); printf(+ Dest IP : %sn,inet_ntoa(packet-ip.destIP); printf(+ Data : %dn,packet-trojan.datalen); printf(+End= +n); #endi

溫馨提示

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

評論

0/150

提交評論