| 0};
char sendSynBuf[128]={0};
char *data="ffantasyYD";
ET_HEADER et_header={0};
IP_HEADER ip_header={0};
TCP_HEADER tcp_header={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_header.m_ver_hlen=(4<<4|5);
ip_header.m_tos=0;
ip_header.m_tlen=htons(sizeof(IP_HEADER)+sizeof(TCP_HEADER)+strlen(data));
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_header.m_dIP=inet_addr(TARGET_IP);
ip_header.m_cksum=CheckSum((USHORT *)&ip_header,sizeof(IP_HEADER));
tcp_header.m_dport=lpTcphdr->m_sport;
tcp_header.m_sport=lpTcphdr->m_dport;
tcp_header.m_seq=lpTcphdr->m_ack; //序列号为接收到包的ack号
if(lpTcphdr->m_res2_flag==0x12) //若收到的包是SYN+ACK包,则ACK号为接收到包的序列号加1
tcp_header.m_ack=htonl(ntohl(lpTcphdr->m_seq)+1);
else //若收到的包不是SYN+ACK包,则ACK号为接收到包的序列号加上包的数据部分长度
tcp_header.m_ack=htonl(ntohl(lpTcphdr->m_seq)+ntohs(lpIphdr->m_tlen)-40);
tcp_header.m_hlen_res4=((sizeof(TCP_HEADER)/4)<<4);
tcp_header.m_res2_flag=0x10; //设置为ACK包
tcp_header.m_win=lpTcphdr->m_win;
tcp_header.m_cksum=0;
tcp_header.m_urp=0;
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |