winpcap发包问题,怎样发送一个带RST标志的TCP包
截获报文后,我想限制网上其他用户对因特网的访问权限。因此我构造了一份自己的报文。
发包的步骤我相信是一样的,主要如下代码
//构造一份报文
IP_HEADER ipHeader;
TCP_HEADER tcpHeader;
PSD_HEADER psdHeader;
char szSendBuf[100]={0};
//填充IP首部
ipHeader.h_lenver=(4<<4 | sizeof(ipHeader)/sizeof(unsigned long));
// ipHeader.tos=0;
ipHeader.tot_len=htons(sizeof(ipHeader)+sizeof(tcpHeader));
ipHeader.id=1;
ipHeader.frag_off=0;
ipHeader.ttl=128;
ipHeader.protocol=IPPROTO_TCP;
ipHeader.check=0;
ipHeader.saddr=pIpHdr->saddr;
ipHeader.daddr=pIpHdr->daddr;
//填充TCP首部
tcpHeader.dest=pTcpHdr->source;//源端口号,
tcpHeader.source=pTcpHdr->dest;//目的端口号 tcpHeader.seq=pTcpHdr->seq;//32位序列号
tcpHeader.ack_seq=0;//32位确认号
tcpHeader.th_lenres=(sizeof(tcpHeader)/4<<4|0);
tcpHeader.th_flag=4; //修改这里来实现不同的标志位探测,2是SYN,1是FIN,16是ACK,4是RST
tcpHeader.window=htons(512);
tcpHeader.urg_ptr=0;
tcpHeader.check=0;
//填充TCP伪首部
psdHeader.saddr=ipHeader.saddr;
psdHeader.daddr=ipHeader.daddr;
psdHeader.mbz=0;
psdHeader.ptcl=IPPROTO_TCP;
psdHeader.tcpl=htons(sizeof(tcpHeader));
//计算校验和
memcpy(szSendBuf, &psdHeader, sizeof(psdHeader));
memcpy(szSendBuf+sizeof(psdHeader), &tcpHeader, sizeof(tcpHeader));
tcpHeader.check=checksum((USHORT *)szSendBuf,sizeof(psdHeader)+sizeof(tcpHeader));
memcpy(szSendBuf, &ipHeader, sizeof(ipHeader));
memcpy(szSendBuf+sizeof(ipHeader), &tcpHeader, sizeof(tcpHeader));
memset(szSendBuf+sizeof(ipHeader)+sizeof(tcpHeader), 0, 4);
ipHeader.check=checksum((USHORT *)szSendBuf, sizeof(ipHeader)+sizeof(tcpHeader));
memcpy(szSendBuf, &ipHeader, sizeof(ipHeader));
//使用winpcap库函数发送包
LPPACKET pPacket;
if((pPacket = PacketAllocatePacket())==NULL)
{
AfxMessageBox("\nError:failed to allocate the LPPACKET structure.");
return ;
}
memset(pPacket,0,sizeof(LPPACKET));
pPacket->Buffer=szSendBuf;
PacketInitPacket(pPacket,pPacket->Buffer,strlen(szSendBuf));
// capture the packet
if(PacketSetNumWrites(lpAdapter,2)==FALSE)
{
AfxMessageBox("warning: Unable to send more than one packet in a single write!\n");
}
if(PacketSendPacket(lpAdapter,pPacket,TRUE)==FALSE)
{
AfxMessageBox("Error sending the packets!\n");
return ;
}
我的问题是:
1。是否发送带RST标志的TCP包后,系统会重起。(还是只是对当前IP包的限制?)
2。是否还有更好的限制访问的方法,(考虑时间和投入,不用驱动和防火墙等)