void CNetHackerDlg::OnStartstopButton()
{
// TODO: Add your control notification handler code here
char adapter[200];
struct sockaddr_in sin;
m_adapterList.GetWindowText(adapter, 200);
if (m_runStatus == STOP)
{
lpadapter = PacketOpenAdapter(adapter);
if (!lpadapter || (lpadapter->hFile == INVALID_HANDLE_VALUE))
{
MessageBox("PacketOpenAdapter Error", "网络黑手", MB_ICONEXCLAMATION);
return ;
}
if ((lppackets = PacketAllocatePacket()) == FALSE)
{
MessageBox("PacketAllocatePacket send Error", "网络黑手", MB_ICONEXCLAMATION);
return ;
}
for (d = alldevs; d; d = d->next)
{
if (strcmp(d->name, adapter) == 0)
{
sin = *(struct sockaddr_in*)(d->addresses->addr);
myip = ntohl(sin.sin_addr.s_addr);
break;
}
}
m_hostList.SetText(1, 0, "正在获取...");
m_hostList.SetText(1, 1, "正在获取...");
m_hostList.Invalidate();
m_fromip.GetAddress(fromip);
m_toip.GetAddress(toip);
m_gateip.GetAddress(gateip);
memset(packetList, 0, MAX_PACKET *sizeof(PacketList));
memset(mmac, 0, 6);
rthread = CreateThread(NULL, 0, sniff, 0, 0, 0);
SetTimer(1, 100, NULL); //启动定时器
SetDlgItemText(IDC_STARTSTOP_BUTTON, "停止");
m_runStatus = START;
}
else
{
TerminateThread(rthread, 0);
CloseHandle(rthread);
TerminateThread(sthread, 0);
CloseHandle(sthread);
currentHstIndex = 0;
sthread = 0;
rthread = 0;
oldHstIndex = 0;
SetDlgItemText(IDC_STARTSTOP_BUTTON, "开始");
m_runStatus = STOP;
PacketCloseAdapter(lpadapter);
KillTimer(1);
}
}