求助
我最近用VC++6.0中的MFC 做了一个多线程的端口扫描程序,不过测试不出来.用断点测试发现是下面的代码有问题:UINT MyScanThread(LPVOID pParam)
{
THREADPARAM* param=(THREADPARAM*)pParam;
ASSERT(pParam);
Cscanner *dlg=param->dlg;
int currentip[4];
UINT port;
CString ip;
CString result;
unsigned int b,e,c;
b=(param->m_BBeginSegAddress[0]<<24)+(param->m_BBeginSegAddress[1]<<16)+
(param->m_BBeginSegAddress[2]<<8)+param->m_BBeginSegAddress[3];
e=(param->m_BEndSegAddress[0]<<24)+(param->m_BEndSegAddress[1]<<16)+
(param->m_BEndSegAddress[2]<<8)+param->m_BEndSegAddress[3];
for(c=b;c<=e;c++)
{
currentip[0]=(c&(255<<24))>>24;
currentip[1]=(c&(255<<16))>>16;
currentip[2]=(c&(255<<8))>>8;
currentip[3]=c&255;
ip.Format("%d.%d.%d.%d",currentip[0],currentip[1],currentip[2],currentip[3]);
result="";
for(port=dlg->m_uPortBegin;port<=dlg->m_uPortEnd;port++)
{
if(dlg->m_bStop)
{
global_criticalsection.Lock();
dlg->m_result+=result;
dlg->SetDlgItemText(IDC_RESULT,dlg->m_result);
global_criticalsection.Unlock();
break;
}
CSocket socket;
if(socket.Create()==false)
{
result+="socket create error!\n";
dlg->SetDlgItemText(IDC_RESULT,dlg->m_result);
AfxMessageBox("socket create error!");
return 0;
}
if(socket.Connect(ip,port)==FALSE)
{
socket.Close();
continue;
}
char buffer[256];
memset(buffer,'\0',256);
if(socket.Receive(buffer,256,0)==SOCKET_ERROR)
{
socket.Close();
continue;
}
CString p;
p.Format("%d",port);
result=result+ip+" 端口:"+p+"的响应信息为:"+buffer+"\r\n";
global_criticalsection.Lock();
dlg->m_result+=result;
dlg->SetDlgItemText(IDC_RESULT,dlg->m_result);
global_criticalsection.Unlock();
}
}
dlg->SetWindowText("扫描结束!");
return 0;
麻烦帮忙看一下,不胜感激.