91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.45MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2023-10-29
  • 語言: 其他
  • 標簽: TCP??報文??源碼??文檔??

資源簡介

發送TCP數據包 設計題目 本設計的目的是填充一個TCP數據包,并發送給目的主機。 1) 以命令行形式運行:SendTCP source_ip source_port dest_ip dest_port Data 其中SendTCP為程序名,source_ip、source_port、dest_ip和dest_port分別為源IP地址、目的IP地址、源端口和目的端口, Data為數據字段。 2)其他的TCP頭部參數請自行設定。 3)數據字段為“This is my homework of network,I am very happy!”。 4)成功發送后在屏幕上輸出“send OK”。

資源截圖

代碼片段和文件信息

#include??
#include??
#include??
#include?
#include?
#include?
#include?
#include?
#pragma?comment(lib“ws2_32.lib“)

#define?IPVER???4???????????//IP協議預定
#define?MAX_BUFF_LEN?65500??//發送緩沖區最大值

typedef?struct?ip_hdr????//定義IP首部?
{?
UCHAR?h_verlen;????????????//4位首部長度4位IP版本號?
UCHAR?tos;????????????????//8位服務類型TOS?
USHORT?total_len;????????//16位總長度(字節)?
USHORT?ident;????????????//16位標識?
USHORT?frag_and_flags;????//3位標志位?
UCHAR?ttl;????????????????//8位生存時間?TTL?
UCHAR?proto;????????????//8位協議?(TCP?UDP?或其他)?
USHORT?checksum;????????//16位IP首部校驗和?
ULONG?sourceIP;????????????//32位源IP地址?
ULONG?destIP;????????????//32位目的IP地址?
}IP_HEADER;?

typedef?struct?tsd_hdr?//定義TCP偽首部?
{?
ULONG?saddr;????//源地址
ULONG?daddr;????//目的地址?
UCHAR?mbz;????????//沒用
UCHAR?ptcl;????????//協議類型?
USHORT?tcpl;????//TCP長度?
}PSD_HEADER;?

typedef?struct?tcp_hdr?//定義TCP首部?
{?
USHORT?th_sport;????????????//16位源端口?
USHORT?th_dport;????????????//16位目的端口?
ULONG?th_seq;????????????????//32位序列號?
ULONG?th_ack;????????????????//32位確認號?
UCHAR?th_lenres;????????????//4位首部長度/6位保留字?
UCHAR?th_flag;????????????????//6位標志位?
USHORT?th_win;????????????????//16位窗口大小?
USHORT?th_sum;????????????????//16位校驗和?
USHORT?th_urp;????????????????//16位緊急數據偏移量?
}TCP_HEADER;?

//CheckSum:計算校驗和的子函數?
USHORT?checksum(USHORT?*buffer?int?size)?
{?
????unsigned?long?cksum=0;?
????while(size?>1)?
????{?
????????cksum+=*buffer++;?
????????size?-=sizeof(USHORT);?
????}?
????if(size)?
????{?
????????cksum?+=?*(UCHAR*)buffer;?
????}?

????cksum?=?(cksum?>>?16)?+?(cksum?&?0xffff);?
????cksum?+=?(cksum?>>16);?
????return?(USHORT)(~cksum);?
}?

int?main(int?argc?char*?argv[])?
{?
????WSADATA?WSAData;?
????SOCKET?sock;?
????
????IP_HEADER?ipHeader;?
????TCP_HEADER?tcpHeader;?
????PSD_HEADER?psdHeader;?

????char?Sendto_Buff[MAX_BUFF_LEN];??//發送緩沖區
????unsigned?short?check_Buff[MAX_BUFF_LEN];?//檢驗和緩沖區
????const?char?tcp_send_data[]={“This?is?my?homework?of?networtI?am?happy!“};

????BOOL?flag;?
????int?rectnTimeOver;?

????if?(argc!=?5)?
????{
????????printf(“Useage:?SendTcp?soruce_ip?source_port?dest_ip?dest_port?\n“);?
????????return?false;?
????}?

????if?(WSAStartup(MAKEWORD(22)?&WSAData)!=0)?
????{?
????????printf(“WSAStartup?Error!\n“);?
????????return?false;?
????}?
if((sock=WSASocket(AF_INETSOCK_RAWIPPROTO_RAWNULL0
WSA_FLAG_OVERLAPPED))==INVALID_SOCKET)?
????{?
????????printf(“Socket?Setup?Error!\n“);?
????????return?false;?
????}?
????flag=true;?
????if(setsockopt(sockIPPROTO_IPIP_HDRINCL(char*)&flagsizeof(flag))==SOCKET_ERROR)?
????{?
????????printf(“setsockopt?IP_HDRINCL?error!\n“);?
????????return?false;?
????}?
????nTimeOver=1000;?
????if?(setsockopt(sock?SOL_SOCKET?SO_SNDTIMEO?(char*)&nTimeOver?sizeof(nTimeOver))==SOCKET_ERROR)?
????{?
????????printf(“setsockopt?SO_SNDTIMEO?error!\n“);?
????????return?fal

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????77312??2004-01-01?01:42??SendTcp\SendTcp.doc
?????目錄???????????0??2015-06-01?10:30??SendTcp\SendTcp\
?????目錄???????????0??2015-06-01?10:30??SendTcp\SendTcp\Debug\
?????文件??????176187??2010-12-22?12:33??SendTcp\SendTcp\Debug\SendTcp.exe
?????文件??????184524??2010-12-22?12:33??SendTcp\SendTcp\Debug\SendTcp.ilk
?????文件???????17290??2010-12-22?12:33??SendTcp\SendTcp\Debug\sendTcp.obj
?????文件?????3727052??2010-12-22?12:33??SendTcp\SendTcp\Debug\SendTcp.pch
?????文件??????353280??2010-12-22?12:33??SendTcp\SendTcp\Debug\SendTcp.pdb
?????文件??????164864??2010-12-22?13:02??SendTcp\SendTcp\Debug\vc60.idb
?????文件???????94208??2010-12-22?12:33??SendTcp\SendTcp\Debug\vc60.pdb
?????文件????????6114??2010-12-22?12:32??SendTcp\SendTcp\sendTcp.cpp
?????文件????????4296??2010-12-22?12:33??SendTcp\SendTcp\SendTcp.dsp
?????文件?????????522??2010-12-22?12:32??SendTcp\SendTcp\SendTcp.dsw
?????文件???????41984??2010-12-22?13:02??SendTcp\SendTcp\SendTcp.ncb
?????文件???????48640??2010-12-22?13:02??SendTcp\SendTcp\SendTcp.opt
?????文件?????????248??2010-12-22?13:02??SendTcp\SendTcp\SendTcp.plg

評論

共有 條評論