2 u013245671 u013245671 于 2015.05.30 16:23 提问

急!!!在线等!!嗅探器点击列表程序出问题

在自己做的嗅探器中点击获取到的信息的其中一条,程序会出现问题。
显示“基础类应用程序已停止工作”(问题应该出在OSPF处)
代码如下:
//处理信息并把数据显示到列表中
void CCapturePacketDlg::processPacket(const pcap_pkthdr *pkt_header, const u_char *pkt_data)
{
struct pcap_pkthdr *pHeader = new pcap_pkthdr;
u_char *pData;
unsigned char *pPosition = (unsigned char *)pkt_data;

long nIndex = 0;//标识当前的数据包位置
long nCount = 0;//标识后来
char strData[20];//标识数据

pHeader->caplen=pkt_header->caplen;    
pHeader->len=pkt_header->len;           

pData=new unsigned char[pHeader->len];    
memcpy((void *)pData,pkt_data,pHeader->len);

m_pktHeaders.Add(pHeader);     //这两个都是数组
m_pktDatas.Add(pData);

nIndex=m_pktHeaders.GetSize()-1;
sprintf(strData,"%07d",nIndex+1);  
nCount=m_listPacket.InsertItem(nIndex,strData,0);             
m_lTotalCount++;                                              
CFramePacket *pFramePacket = new CFramePacket(pData,14);      /
CString strStamp;
struct tm *ltime;                                             //时间戳   
ltime=localtime(&pkt_header->ts.tv_sec);                      //获取时间
strStamp.Format("%d-%d-%d %d:%d:%d",ltime->tm_year+1900,ltime->tm_mon+1,ltime->tm_mday,ltime->tm_hour,ltime->tm_min,ltime->tm_sec);
CString strLength;                                              
strLength.Format("%ld",pHeader->len);
m_listPacket.SetItemText(nCount,1,strStamp);
m_listPacket.SetItemText(nCount,2,pFramePacket->GetMacSrcAddr());
m_listPacket.SetItemText(nCount,3,pFramePacket->GetMacDestAddr());
m_listPacket.SetItemText(nCount,4,strLength);
if(pFramePacket->GetType() == 0x0800)                           
{
    CIPPacket ipPacket(pData+14,pHeader->len-14);
    m_listPacket.SetItemText(nCount,5,ipPacket.GetProtocol());  //显示协议类型(TCP+TCP+OSPF)
    m_listPacket.SetItemText(nCount,7,ipPacket.GetSrcIP());
    m_listPacket.SetItemText(nCount,8,ipPacket.GetDestIP());
    if(ipPacket.GetProtocol() == "UDP")
    {
        CUDPPacket *pUDPPacket = new CUDPPacket(ipPacket.GetTData(),ipPacket.GetDataLength());
        m_listPacket.SetItemText(nCount,6,pUDPPacket->GetSrcPort());
        m_listPacket.SetItemText(nCount,9,pUDPPacket->GetDestPort());
        delete pUDPPacket;
        pUDPPacket = NULL;
        m_lUdpCount++;//UDP包加1
    }
    else if(ipPacket.GetProtocol() == "TCP")
    {
        CTCPPacket *pTCPPacket = new CTCPPacket(ipPacket.GetTData(),ipPacket.GetDataLength());
        m_listPacket.SetItemText(nCount,6,pTCPPacket->GetSrcPort());
        m_listPacket.SetItemText(nCount,9,pTCPPacket->GetDestPort());
        delete pTCPPacket;
        pTCPPacket = NULL;
        m_lTcpCount++;//TCP包加1
    }
    else if(ipPacket.GetProtocol() == "OSPF")
    {
        COSPFPacket *pOSPFPacket = new COSPFPacket(ipPacket.GetTData(),ipPacket.GetDataLength());
        delete pOSPFPacket;
        pOSPFPacket = NULL;
        m_lOspfCount++;//OSPF包加1
    }

}
else if(pFramePacket->GetType() == 0x0806)                          ////如果是ARP数据包
{
    m_listPacket.SetItemText(nCount,5,"ARP");
    CARPPacket *pARPPacket = new CARPPacket(pData+14,pHeader->len-14);
    m_listPacket.SetItemText(nCount,7,pARPPacket->GetSPAddr());
    m_listPacket.SetItemText(nCount,8,pARPPacket->GetDPAddr());
    delete pARPPacket;
    pARPPacket = NULL;
    m_lArpCount++;//ARP包加1
}
else
{
    CString strProtocol;
    strProtocol.Format("0X%x",pFramePacket->GetType());
    m_listPacket.SetItemText(nCount,5,strProtocol);
    m_lOtherCount++;
}
delete pFramePacket;
pFramePacket = NULL;    
ShowPacketCount();//显示统计量信息

}

//将数据内容显示到协议树上
void CCapturePacketDlg::ShowPacketForTree(const pcap_pkthdr *pkt_header, const u_char *pkt_data,long index)
{
m_treeSingerPacket.DeleteAllItems();
CString strTitle;
strTitle.Format("第%ld个数据包",index+1); //title
HTREEITEM hRoot = m_treeSingerPacket.InsertItem(strTitle); //树的根节点句柄
HTREEITEM hSubItem = m_treeSingerPacket.InsertItem("链路层数据",hRoot); //分支的
CFramePacket *pFramePacket = new CFramePacket(pkt_data,14); //再次与链路层打交道,获取链路层信息。
HTREEITEM hItem = m_treeSingerPacket.InsertItem("源MAC地址 : "+pFramePacket->GetMacSrcAddr(),hSubItem); //细化信息
hItem = m_treeSingerPacket.InsertItem("目的MAC地址 : "+pFramePacket->GetMacDestAddr(),hSubItem);
CString strType;
strType.Format("类型 : 0X%x",pFramePacket->GetType());
hItem = m_treeSingerPacket.InsertItem(strType,hSubItem);

if(pFramePacket->GetType() == 0x0800)             //当时IP数据报时,显示网络层信息
{
    hSubItem = m_treeSingerPacket.InsertItem("网络层数据",hRoot);
    CIPPacket ipPacket(pkt_data+14,pkt_header->len-14);
    hItem = m_treeSingerPacket.InsertItem("协议 : IP",hSubItem);                         //应该是按顺序来的
    hItem = m_treeSingerPacket.InsertItem("源IP : "+ipPacket.GetSrcIP(),hSubItem);
    hItem = m_treeSingerPacket.InsertItem("目的IP : "+ipPacket.GetDestIP(),hSubItem);
    hItem = m_treeSingerPacket.InsertItem("版本号: "+ipPacket.GetVersion(),hSubItem);
    if(ipPacket.GetProtocol() == "UDP")
    {           
        CUDPPacket *pUDPPacket = new CUDPPacket(ipPacket.GetTData(),ipPacket.GetDataLength());
        hItem = m_treeSingerPacket.InsertItem("协议 : UDP",hSubItem);
        hItem = m_treeSingerPacket.InsertItem("源端口 : "+pUDPPacket->GetSrcPort(),hSubItem);
        delete pUDPPacket;
        pUDPPacket = NULL;
        }
            else if(ipPacket.GetProtocol() == "OSPF")                //OSPF数据包协议树显示
    {
        COSPFPacket *pOSPFPacket = new COSPFPacket(ipPacket.GetTData(),ipPacket.GetDataLength());
        hItem = m_treeSingerPacket.InsertItem("协议 : OSPF",hSubItem);
        hItem = m_treeSingerPacket.InsertItem("版本 : "+pOSPFPacket->GetVersion(),hSubItem);
        hItem = m_treeSingerPacket.InsertItem("报文类型 : "+pOSPFPacket->GetPacketType(),hSubItem);
        hItem = m_treeSingerPacket.InsertItem("报文长度 : "+pOSPFPacket->GetPacketLength(),hSubItem);
        hItem = m_treeSingerPacket.InsertItem("RouterID : "+pOSPFPacket->GetRouterID(),hSubItem);
        hItem = m_treeSingerPacket.InsertItem("区域号: "+pOSPFPacket->GetAreaID(),hSubItem);
        hItem = m_treeSingerPacket.InsertItem("校验和 : "+pOSPFPacket->GetCheckSum(),hSubItem);
        hItem = m_treeSingerPacket.InsertItem("认证类型 : "+pOSPFPacket->GetAuType(),hSubItem);
        if(pOSPFPacket->GetPacketType() =="HELLO")              //如果OSPF的报文类型为Hello时
        {
            COspfHello *pHelloPacket=new COspfHello(pOSPFPacket->GetHData(),pOSPFPacket->GetDataLength());  

            hItem = m_treeSingerPacket.InsertItem("子网掩码 : "+pHelloPacket->GetNetMask(),hSubItem);
            hItem = m_treeSingerPacket.InsertItem("Hello时间 : "+pHelloPacket->GetHelloInterval(),hSubItem);
            hItem = m_treeSingerPacket.InsertItem("选项: "+pHelloPacket->GetOption(),hSubItem);
            hItem = m_treeSingerPacket.InsertItem("优先级: "+pHelloPacket->GetPriority(),hSubItem);
            hItem = m_treeSingerPacket.InsertItem("失效时间: "+pHelloPacket->GetPriority(),hSubItem);
            hItem = m_treeSingerPacket.InsertItem("DR: "+pHelloPacket->GetDR(),hSubItem);
            hItem = m_treeSingerPacket.InsertItem("BDR: "+pHelloPacket->GetBDR(),hSubItem);
            hItem = m_treeSingerPacket.InsertItem("邻居: "+pHelloPacket->GetNeighbor(),hSubItem);
            delete pHelloPacket;
            pHelloPacket=NULL;
        }
        else
        {

        }
        delete pOSPFPacket;
        pOSPFPacket = NULL; 
    }
    m_treeSingerPacket.Expand(hSubItem,TVE_EXPAND);
}

}

Csdn user default icon
上传中...
上传图片
插入图片