| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 389 人关注过本帖
标题:求助
只看楼主 加入收藏
renjiajia
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-5-4
收藏
 问题点数:0 回复次数:1 
求助
我最近用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;
麻烦帮忙看一下,不胜感激.
搜索更多相关主题的帖子: result 多线程 断点 
2008-05-25 07:35
flyue
Rank: 10Rank: 10Rank: 10
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
注 册:2006-6-20
收藏
得分:0 
哪句代码有问题?

天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
2008-05-25 16:45
快速回复:求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016899 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved