版主大人Kingzai:请帮我调试一下,在RAW_SOCKET成功,但winpcap却不成,为什么?
#define SENDBUFLENG 64
eth.eh_dst[0]=0x00;//目标MAC(192.168.9.250地址)
eth.eh_dst[1]=0x05;
eth.eh_dst[2]=0x5d;
eth.eh_dst[3]=0x22;
eth.eh_dst[4]=0xfb;
eth.eh_dst[5]=0xa0;
eth.eh_src[0]=0x00;//发方MAC(192.168.9.180地址)
eth.eh_src[1]=0x50;
eth.eh_src[2]=0xeb;
eth.eh_src[3]=0x03;
eth.eh_src[4]=0x5b;
eth.eh_src[5]=0xb1;
eth.eh_type=htons(ETH_IP);//协议类型
memcpy(sendbuf,ð,sizeof(eth));
ipHeader.h_lenver=(4<<4 | sizeof(ipHeader)/sizeof(unsigned long));
ipHeader.tos=0;
ipHeader.total_len=SENDBUFLENG;
ipHeader.ident=(USHORT)GetCurrentProcessId();
ipHeader.frag_and_flags=0;
ipHeader.ttl=128;
ipHeader.proto=IPPROTO_ICMP;
ipHeader.sourceIP=inet_addr("192.168.9.180");
ipHeader.destIP=inet_addr("192.168.9.250");
ipHeader.checksum=0;
icmpHeader.i_type=ICMP_ECHO;
icmpHeader.i_code=0;
icmpHeader.i_cksum=0;
icmpHeader.i_id=(USHORT)GetCurrentProcessId();
icmpHeader.i_seq=0x00;
icmpHeader.Data=0;
memset(szsendbuf, 0, SENDBUFLENG);
memcpy(szsendbuf,&ipHeader,sizeof(IP_HEADER));
memcpy(szsendbuf+sizeof(IP_HEADER),&icmpHeader,sizeof(icmpHeader));
icmpHeader.i_cksum=checksum((USHORT*)(szsendbuf+sizeof(IP_HEADER)),SENDBUFLENG-sizeof(IP_HEADER));
ipHeader.checksum=checksum((USHORT*)szsendbuf,sizeof(IP_HEADER));
memcpy(szsendbuf,&ipHeader,sizeof(IP_HEADER));
memcpy(szsendbuf+sizeof(IP_HEADER),&icmpHeader,sizeof(icmpHeader));
PacketInitPacket(lppackets,sendbuf,sizeof(eth)+SENDBUFLENG);
PacketSendPacket(lpadapter,lppackets,TRUE);
PING 路由器时,返回数据被本机抛弃
问题点数:0、回复次数:3Top
1 楼wjl_2001(wjl_2001)回复于 2003-05-04 21:52:55 得分 0
哪只恶狗在这儿乱吠?Top
2 楼kingzai(stevenzhu)回复于 2003-05-05 14:58:15 得分 0
前面的代码没有错误,发包的时候不对,应该是
//使用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 ;
}
Top




