www.pudn.com > TCPIPAnalyse1.rar > IrisAnalyseDoc.cpp


// IrisAnalyseDoc.cpp : implementation of the CIrisAnalyseDoc class 
// 
 
#include "stdafx.h" 
#include "IrisAnalyse.h" 
 
#include "IrisAnalyseDoc.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
#ifndef uchar 
#define uchar unsigned char 
#endif 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CIrisAnalyseDoc 
 
IMPLEMENT_DYNCREATE(CIrisAnalyseDoc, CDocument) 
 
BEGIN_MESSAGE_MAP(CIrisAnalyseDoc, CDocument) 
	//{{AFX_MSG_MAP(CIrisAnalyseDoc) 
	ON_COMMAND(ID_FILE_SAVE, OnFileSave) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CIrisAnalyseDoc construction/destruction 
 
CIrisAnalyseDoc::CIrisAnalyseDoc() 
{ 
	// TODO: add one-time construction code here 
	memset(&m_sHead,0,sizeof(IRISHEAD)); 
	m_pLeftDataHead = NULL; 
	m_pRightDataHead = NULL; 
 
} 
 
CIrisAnalyseDoc::~CIrisAnalyseDoc() 
{ 
} 
 
BOOL CIrisAnalyseDoc::OnNewDocument() 
{ 
	if (!CDocument::OnNewDocument()) 
		return FALSE; 
	//文档标题风格 
	//SetTitle ("监控数据包分析"); 
/*	// TODO: add reinitialization code here 
	// (SDI documents will reuse this document) 
	//显示文档次序 
	static int count=0; 
	char message[10]; 
	wsprintf (message,"%s%d","文档",count); 
	SetTitle (message); 
	count++; 
*/ 
	return TRUE; 
} 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CIrisAnalyseDoc serialization 
 
void CIrisAnalyseDoc::Serialize(CArchive& ar) 
{ 
 
	if (ar.IsLoading()) 
	{ 
		// TODO: add storing code here 
		CFile* pFile = ar.GetFile (); 
		//CString aa=pFile->GetFilePath(); 
        m_nFileLength = (UINT) pFile->GetLength (); 
 
        // Allocate a buffer for the file data. 
        try  
		{ 
            m_pFileData = new BYTE[m_nFileLength]; 
        } 
        catch (CMemoryException* e)  
		{ 
            m_nFileLength = 0; 
            throw e; 
        } 
 
        // Read the file data into the buffer. 
        try  
		{ 
            pFile->Read (m_pFileData, m_nFileLength); 
        } 
        catch (CFileException* e)  
		{ 
            delete[] m_pFileData; 
            m_pFileData = NULL; 
            m_nFileLength = 0; 
            throw e; 
        } 
		//分析数据 
		AnalyseData(m_pFileData,m_nFileLength); 
	} 
	else 
	{ 
		 
		// TODO: add loading code here 
		//save left and righe data 
		if(SaveType==0)	   SaveLeftFile(ar); 
		if(SaveType==1)    SaveRightFile(ar); 
	 
	} 
} 
void CIrisAnalyseDoc::OnFileSave()  
{ 
	// TODO: Add your command handler code here 
	CFileDialog my(FALSE); 
	if(my.DoModal()==IDOK) 
	{ 
		CString FileName=my.GetFileName(); 
		SaveType=0; 
		CString LeftFile=FileName; 
		OnSaveDocument(LeftFile); 
		SaveType=1; 
		CString RightFile=FileName; 
		OnSaveDocument(RightFile); 
	} 
} 
void CIrisAnalyseDoc::SaveLeftFile(CArchive &ar) 
{ 
	AfxMessageBox("save Left data"); 
	TCPIPPKG* pl; 
	pl = m_pLeftDataHead; 
	CString strl; 
	int lenthl; 
	CFile* DesFileL = ar.GetFile (); 
		do 
		{ 
			lenthl = pl->DataLen; 
			strl = pl->databuff; 
			DesFileL->Write(strl,lenthl); 
			pl = pl->next; 
		}while(pl != NULL); 
} 
void CIrisAnalyseDoc::SaveRightFile(CArchive &ar) 
{ 
	AfxMessageBox("save Right data"); 
	TCPIPPKG*pr; 
	pr = m_pRightDataHead; 
	CString strr; 
	int lenthr; 
	CFile* DesFileR = ar.GetFile (); 
		do 
		{ 
			lenthr = pr->DataLen; 
			strr = pr->databuff; 
			DesFileR->Write(strr,lenthr); 
			pr = pr->next; 
		}while(pr != NULL); 
 
} 
///////////////////////////////////////////////////////////////////////////// 
// CIrisAnalyseDoc diagnostics 
 
#ifdef _DEBUG 
void CIrisAnalyseDoc::AssertValid() const 
{ 
	CDocument::AssertValid(); 
} 
 
void CIrisAnalyseDoc::Dump(CDumpContext& dc) const 
{ 
	CDocument::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CIrisAnalyseDoc commands 
// 
// 分析数据 
// Global variable is m_pLeftDataHead and m_pRightDataHead 
// 
void CIrisAnalyseDoc::AnalyseData(BYTE *pFileData,UINT nFileLength) 
{ 
	TCPIPPKG *pTempHead; 
	TCPIPPKG *pl1,*pl2; 
	TCPIPPKG *pr1,*pr2; 
	unsigned char *pBuffer=pFileData;//obtain start address 
	unsigned char *startBuffer=pFileData;//record start address 
	int i,No=1; 
	int nMacIpTcpDataLen,nIpTcpDataLen; 
	int nFlag=0; 
	unsigned char temp[20]; 
	unsigned char bakTimeBuff[10],bakMacDesAddr[6],bakMacSrcAddr[6],bakMactoCmp[20],tranMac[20]; 
 
#define TIMELEN		10 
#define MACLEN		6 
#define NETTYPELEN	2 
#define IPADDRLEN	4 
 
	pl1=pl2=(pTCPIPPKG )malloc(sizeof(TCPIPPKG)); 
	pr1=pr2=(pTCPIPPKG )malloc(sizeof(TCPIPPKG)); 
 
	//Package head 
	for(i=0;i<9;i++) 
	{ 
		m_sHead.buff[i] = *pBuffer++; 
	} 
	//start for(;;) 
	for(;;) 
	{ 
		int nLeft,nRight; 
		int niptcpheadlen,nipheadlen=20,ntcpheadlen=20; 
		//if no data 
		if((UINT)(pBuffer - startBuffer) > (nFileLength-1)) 
		{ 
			break; 
		} 
 
		//1.Package Len = 2byte(from mac to data) 
		temp[0] = *pBuffer++;	//2 
		temp[1] = *pBuffer++; 
		temp[2] = '\0'; 
		nMacIpTcpDataLen = temp[1]; 
		nMacIpTcpDataLen = nMacIpTcpDataLen << 8 | temp[0]; 
	 
		//2.Package time = 10byte 
		for(i=0;iNum = No; 
			No++; 
			//2.Package time = 10byte 
			for(i=0;i<10;i++) 
			{ 
				pl1->TimeBuff[i] = bakTimeBuff[i]; 
			} 
		    //::lstrcpy(pl1->TimeBuff,bakTimeBuff); 
/////////////////////////////////////////////////////////// 
			//3.See MAC structure 
			for(i=0;imacpkg.SrcAddr[i] = bakMacSrcAddr[i]; 
			} 
			//::lstrcpy(pl1->macpkg.SrcAddr,bakMacDesAddr); 
			for(i=0;imacpkg.DesAddr[i] = bakMacDesAddr[i]; 
			} 
         
#ifdef DEBUG1 
 
{ 
char debugetemp[6]; 
sprintf(debugetemp,"%x %x %x %x %x %x", 
            (uchar)pl1->macpkg.SrcAddr[0], 
			(uchar)pl1->macpkg.SrcAddr[1], 
		    (uchar)pl1->macpkg.SrcAddr[2], 
			(uchar)pl1->macpkg.SrcAddr[3], 
			(uchar)pl1->macpkg.SrcAddr[4], 
			(uchar)pl1->macpkg.SrcAddr[5]); 
AfxMessageBox(debugetemp); 
} 
#endif 
	 
			for(i=0;imacpkg.NetType[i] = *pBuffer++; 
			} 
			 
#ifdef DEBUG1 
 
			 
{ 
char debugetemp[2]; 
sprintf(debugetemp,"%x %x", 
       (uchar)pl1->macpkg.NetType[0], 
	   (uchar)pl1->macpkg.NetType[1]); 
AfxMessageBox(debugetemp); 
} 
#endif		 
/////////////////////////////////////////////////////// 
//===================================================add by chenjw 
//------------if ARP --judge arp 
			if(((uchar)pl1->macpkg.NetType[0] == 0x08) && ((uchar)pl1->macpkg.NetType[1] == 0x06)) 
			{ 
				pBuffer += 14; 
				for (int nARP1 = 0;nARP1 < 4;nARP1++) 
				{ 
					pl1->ippkg.srcIP[nARP1] = *pBuffer++; 
				} 
	 
				pBuffer += 6; 
				for (int nARP2 = 0;nARP2 < 4;nARP2++) 
				{ 
					pl1->ippkg.desIP[nARP2] = *pBuffer++; 
				} 
				pBuffer += 18; 
				pl1->tcppkg.SrcPort = 0; 
				pl1->tcppkg.DesPort = 0; 
				pl1->DataLen = 0; 
				pl1->nLine = 0; 
			} 
			else if(pl1->macpkg.NetType[0] == 0x08 &&pl1->macpkg.NetType[1] == 0x00) 
			{// judge tcp/udp---add by chenjw 
		 
				//4.See IP structure 
			   //pBuffer += 2; x 
				pl1->ippkg.HeaderLen = int(*pBuffer++ &0x0f); 
				pl1->ippkg.TypeService = *pBuffer++; 
				//if(pl1->ippkg.HeaderLen==6) 
				//	nipheadlen=24; 
/*{	 
char debugtemp[5]; 
sprintf(debugtemp,"%d",pl1->ippkg.HeaderLen); 
AfxMessageBox(debugtemp); 
}*/ 
#ifdef DEBUG1 
 
{ 
char debugetemp[3]; 
sprintf(debugetemp,"%x %x", 
           (uchar)pl1->ippkg.Ver, 
           (uchar)pl1->ippkg.TypeService); 
AfxMessageBox(debugetemp); 
} 
#endif 
			 
				for(i=0;i<2;i++) 
				{ 
					temp[i] = *pBuffer++; 
				} 
				temp[i]='\0'; 
				nIpTcpDataLen=temp[0]; 
				nIpTcpDataLen = nIpTcpDataLen<<8 | temp[1]; 
#ifdef DEBUG1 
{ 
char tempDebug[2]; 
sprintf(tempDebug,"%d",(uchar)nIpTcpDataLen); 
AfxMessageBox(tempDebug); 
} 
		 
{ 
char debugetemp[4]; 
sprintf(debugetemp,"%x %x", 
		(uchar)temp[0],(uchar)temp[1]); 
AfxMessageBox(debugetemp); 
} 
#endif 
 
				//pBuffer += 8; 
				pBuffer += 5; 
				pl1->ippkg.Protocol = *pBuffer++; 
				pBuffer += 2; 
				for(i=0;iippkg.srcIP[i] = *pBuffer++; 
				} 
 
#ifdef DEBUG1 
{ 
char debugetemp[6]; 
sprintf(debugetemp,"%x %x %x %x ", 
        (uchar)pl1->ippkg.srcIP[0], 
		(uchar)pl1->ippkg.srcIP[1], 
		(uchar)pl1->ippkg.srcIP[2], 
		(uchar)pl1->ippkg.srcIP[3]); 
AfxMessageBox(debugetemp); 
} 
#endif 
		 
				for(i=0;iippkg.desIP[i] = *pBuffer++; 
				} 
 
#ifdef DEBUG1 
		 
{ 
char debugetemp[6]; 
sprintf(debugetemp,"%x %x %x %x ", 
        (uchar)pl1->ippkg.desIP[0], 
		(uchar)pl1->ippkg.desIP[1], 
	    (uchar)pl1->ippkg.desIP[2], 
		(uchar)pl1->ippkg.desIP[3]); 
AfxMessageBox(debugetemp); 
} 
#endif 
/////////////////////////////////////////////////////////// 
			//5.See TCP Structure 
				for(i=0;i<2;i++) 
				{ 
					temp[i]=*pBuffer++; 
				} 
				temp[i]='\0'; 
				pl1->tcppkg.SrcPort=temp[0]; 
				pl1->tcppkg.SrcPort = pl1->tcppkg.SrcPort<<8 | temp[1]; 
#ifdef DEBUG1 
{	 
 
char debugtemp[5]; 
sprintf(debugtemp,"%d",pl1->tcppkg.SrcPort); 
AfxMessageBox(debugtemp); 
} 
{ 
char debugtemp[5]; 
sprintf(debugtemp,"%x %x", 
		(uchar)temp[0], 
		(uchar)temp[1]); 
AfxMessageBox(debugtemp); 
} 
#endif 
				for(i=0;i<2;i++) 
				{ 
					temp[i]=*pBuffer++; 
				} 
				temp[i]='\0'; 
				pl1->tcppkg.DesPort=temp[0]; 
				pl1->tcppkg.DesPort = pl1->tcppkg.DesPort<<8 | temp[1]; 
#ifdef DEBUG1 
{ 
char tempDebug[2]; 
sprintf(tempDebug,"%d",pl1->tcppkg.DesPort); 
AfxMessageBox(tempDebug); 
} 
#endif 
		 
#ifdef DEBUG1			 
{ 
char debugtemp[5]; 
sprintf(debugtemp,"%x %x", 
		(uchar)temp[0], 
		(uchar)temp[1]); 
AfxMessageBox(debugtemp); 
} 
#endif 
	 
#ifdef DEBUG1			 
{ 
int nM; 
char debugtemp[20]; 
nM=nIpTcpDataLen - 40; 
sprintf(debugtemp,"%d ",nM); 
AfxMessageBox(debugtemp); 
} 
#endif 
				if(pl1->ippkg.Protocol == 0x06)//judge tcp--add by chenjw 
				{ 
 
					//pBuffer += 16; 
					pBuffer+=8; 
					pl1->tcppkg.HeaderLen=int(*pBuffer++ >>4); 
					pBuffer+=7; 
					//modify by chenjw 
					ntcpheadlen = pl1->tcppkg.HeaderLen * 4; 
					pBuffer += (ntcpheadlen - 20); 
/*					if(pl1->tcppkg.HeaderLen==6) 
					{ 
						ntcpheadlen=24; 
						pBuffer+=4; 
					} 
					else if(pl1->tcppkg.HeaderLen == 8) 
					{ 
						ntcpheadlen = 32; 
						pBuffer += 12; 
					} 
*/ 
/*{char debugtemp[20]; 
sprintf(debugtemp,"%d ",pl1->tcppkg.HeaderLen); 
AfxMessageBox(debugtemp); 
}*/ 
////////////////////////////////////////////////////////// 
					niptcpheadlen=nipheadlen+ntcpheadlen; 
					//6.See Data 
					for(i=0;i <(nIpTcpDataLen - niptcpheadlen);i++) 
					{ 
						pl1->databuff[i] = *pBuffer++; 
					} 
					pl1->DataLen=nIpTcpDataLen-niptcpheadlen; 
 
#ifdef DEBUG1 
{ 
char debugtemp[6]; 
sprintf(debugtemp,"%x %x %x %x %x %x", 
		(uchar)pl1->buff[0],(uchar)pl1->buff[1], 
		(uchar)pl1->buff[2],(uchar)pl1->buff[3], 
		(uchar)pl1->buff[nIpTcpDataLen - 42], 
		(uchar)pl1->buff[nIpTcpDataLen - 41]); 
AfxMessageBox(debugtemp); 
} 
#endif 
 
					int hl=(nMacIpTcpDataLen-nIpTcpDataLen-14);     	 
					pBuffer+=hl; 
 
#ifdef DEBUG1 
{ 
char debugetemp[20]; 
sprintf(debugetemp,"%d ",hl); 
AfxMessageBox("after for Data"); 
AfxMessageBox(debugetemp); 
} 
#endif 
/////////////////////////////////////////////////// 
				//compute and save how many line for data 
					nLeft = ( (nIpTcpDataLen-niptcpheadlen+15)/16); 
					pl1->nLine = nLeft; 
				} 
			 
				else //judge udp---add by chenjw 
				{ 
					//pl1->tcppkg.SrcPort = 0; 
					//pl1->tcppkg.DesPort = 0; 
					pl1->DataLen = 0; 
					pl1->nLine = 0; 
					pBuffer += (nIpTcpDataLen - 20 - 4); 
				}//else -end udp 
			}  //end else--end tcp/udp 
			else 
			{ 
				//int nLogLinctrlLen = pl1->macpkg.NetType[0]<<8 | pl1->macpkg.NetType[1]; 
				pl1->tcppkg.SrcPort =0; 
				pl1->DataLen = 0; 
				pl1->nLine = 0; 
				pl1->ippkg.srcIP[0] = 0x00; 
				pl1->ippkg.srcIP[1] = 0x00; 
				pl1->ippkg.srcIP[2] = 0x00; 
				pl1->ippkg.srcIP[3] = 0x00; 
				pBuffer += (nMacIpTcpDataLen - 14); 
				 
			}//end else---logiclinkcontrol 
///////////////////////////////////////////////////////// 
			//7.Save data 
			if(m_pLeftDataHead == NULL) 
			{ 
				m_pLeftDataHead = pl1; 
			} 
			else 
			{ 
				pl2->next = pl1; 
			} 
			pl2=pl1; 
			pl1=(pTCPIPPKG)malloc(sizeof(TCPIPPKG)); 
		} 
		 
//*************************************************** 
		else//right view 
		{ 
			 
			pr1->Num = No; 
			No++; 
			//2.Package time = 10byte 
			for(i=0;i<10;i++) 
			{ 
				pr1->TimeBuff[i] = bakTimeBuff[i]; 
			} 
			//::lstrcpy(pr1->TimeBuff,bakTimeBuff); 
/////////////////////////////////////////////////// 
			//3.See MAC structure 
			for(i=0;imacpkg.SrcAddr[i] = bakMacSrcAddr[i]; 
			//::lstrcpy(pr1->macpkg.DesAddr,bakMacDesAddr); 
			for(i=0;imacpkg.DesAddr[i] = bakMacDesAddr[i]; 
			} 
#ifdef DEBUG1 
			 
{ 
char debugetemp[6]; 
sprintf(debugetemp,"%x %x %x %x %x %x", 
            (uchar)pr1->macpkg.SrcAddr[0], 
			(uchar)pr1->macpkg.SrcAddr[1], 
		    (uchar)pr1->macpkg.SrcAddr[2], 
			(uchar)pr1->macpkg.SrcAddr[3], 
			(uchar)pr1->macpkg.SrcAddr[4], 
			(uchar)pr1->macpkg.SrcAddr[5]); 
AfxMessageBox(debugetemp); 
} 
#endif 
			for(i=0;imacpkg.NetType[i] = *pBuffer++; 
			} 
#ifdef DEBUG1		 
{ 
char debugetemp[2]; 
sprintf(debugetemp,"%x %x", 
       (uchar)pr1->macpkg.NetType[0], 
	   (uchar)pr1->macpkg.NetType[1]); 
AfxMessageBox(debugetemp); 
} 
#endif 
//////////////////////////////////////////////////////////// 
//===================================================add by chenjw 
//------------if ARP  
			if(((uchar)pr1->macpkg.NetType[0] == 0x08) && ((uchar)pr1->macpkg.NetType[1] == 0x06)) 
			{ 
				pBuffer += 14; 
				for (int nARP1 = 0;nARP1 < 4;nARP1++) 
				{ 
					pr1->ippkg.srcIP[nARP1] = *pBuffer++; 
				} 
	 
				pBuffer += 6; 
				for (int nARP2 = 0;nARP2 < 4;nARP2++) 
				{ 
					pr1->ippkg.desIP[nARP2] = *pBuffer++; 
				} 
				pr1->tcppkg.SrcPort = 0; 
				pr1->tcppkg.DesPort = 0; 
				pr1->DataLen = 0; 
				pr1->nLine = 0; 
				pBuffer += 18; 
				 
			} 
			else if(pr1->macpkg.NetType[0] ==0x08 && pr1->macpkg.NetType[1] == 0x00) 
			{ 
				//4.See IP structure 
				//pBuffer += 2; 
        		//pr1->ippkg.Ver = *pBuffer++; 
				pr1->ippkg.HeaderLen = int(*pBuffer++ &0x0f); 
				pr1->ippkg.TypeService = *pBuffer++; 
				//if(pl1->ippkg.HeaderLen==6) 
				//	nipheadlen=24; 
#ifdef DEBUG1 
{ 
char debugetemp[3]; 
sprintf(debugetemp,"%x %x", 
           (uchar)pr1->ippkg.Ver, 
           (uchar)pr1->ippkg.TypeService); 
AfxMessageBox(debugetemp); 
} 
#endif 
				for(i=0;i<2;i++) 
				{ 
					temp[i] = *pBuffer++; 
				} 
				temp[i]='\0'; 
				nIpTcpDataLen=temp[0]; 
				nIpTcpDataLen = nIpTcpDataLen<<8 | temp[1]; 
#ifdef DEBUG1 
{ 
char tempDebug[2]; 
sprintf(tempDebug,"%d",(uchar)nIpTcpDataLen); 
AfxMessageBox(tempDebug); 
} 
#endif 
				//pBuffer += 8; 
				pBuffer += 5; 
				pr1->ippkg.Protocol = *pBuffer++; 
				pBuffer += 2; 
				for(i=0;iippkg.srcIP[i] = *pBuffer++; 
				} 
#ifdef DEBUG1 
{ 
char debugetemp[6]; 
sprintf(debugetemp,"%x %x %x %x ", 
        (uchar)pr1->ippkg.srcIP[0], 
		(uchar)pr1->ippkg.srcIP[1], 
		(uchar)pr1->ippkg.srcIP[2], 
		(uchar)pr1->ippkg.srcIP[3]); 
AfxMessageBox(debugetemp); 
} 
#endif 
				for(i=0;iippkg.desIP[i] = *pBuffer++; 
				} 
	 
#ifdef DEBUG1 
{ 
char debugetemp[6]; 
sprintf(debugetemp,"%x %x %x %x ", 
        (uchar)pr1->ippkg.desIP[0], 
		(uchar)pr1->ippkg.desIP[1], 
	    (uchar)pr1->ippkg.desIP[2], 
		(uchar)pr1->ippkg.desIP[3]); 
AfxMessageBox(debugetemp); 
} 
#endif 
//////////////////////////////////////////////////////// 
				//5.See TCP Structure 
				for(i=0;i<2;i++) 
				{ 
					temp[i]=*pBuffer++; 
				} 
				temp[i]='\0'; 
				pr1->tcppkg.SrcPort=temp[0]; 
				pr1->tcppkg.SrcPort = pr1->tcppkg.SrcPort<<8 | temp[1]; 
				//pr1->tcppkg.SrcPort = atoi(temp);wrong fation 
#ifdef DEBUG1 
{	 
char debugtemp[5]; 
sprintf(debugtemp,"%d",pr1->tcppkg.SrcPort); 
AfxMessageBox(debugtemp); 
} 
{ 
char debugtemp[5]; 
sprintf(debugtemp,"%x %x", 
		(uchar)temp[0], 
		(uchar)temp[1]); 
AfxMessageBox(debugtemp); 
} 
#endif 
 
				for(i=0;i<2;i++) 
				{ 
					temp[i]=*pBuffer++; 
				} 
				temp[i]='\0'; 
				pr1->tcppkg.DesPort=temp[0]; 
				pr1->tcppkg.DesPort = pr1->tcppkg.DesPort<<8 | temp[1]; 
				//pr1->tcppkg.DesPort = atoi(temp); 
#ifdef DEBUG1 
{ 
char tempDebug[2]; 
sprintf(tempDebug,"%d",pr1->tcppkg.DesPort); 
AfxMessageBox(tempDebug); 
} 
#endif 
#ifdef DEBUG1			 
{ 
char debugtemp[5]; 
sprintf(debugtemp,"%x %x", 
		(uchar)temp[0], 
		(uchar)temp[1]); 
AfxMessageBox(debugtemp); 
}		 
#endif 
#ifdef DEBUG1			 
{ 
int nM; 
char debugtemp[20]; 
nM=nIpTcpDataLen - 40; 
sprintf(debugtemp,"%d ",nM); 
AfxMessageBox(debugtemp); 
}		 
#endif          
////////////////////////////////////////////////////// 
				if (pr1->ippkg.Protocol == 0x06) 
				{ 
         		//pBuffer += 16; 
					pBuffer+=8; 
					pr1->tcppkg.HeaderLen=int(*pBuffer++ >>4); 
					pBuffer+=7; 
					//modify by chenjw 
					ntcpheadlen = pr1->tcppkg.HeaderLen * 4; 
					pBuffer += (ntcpheadlen - 20); 
/* 
					if(pr1->tcppkg.HeaderLen==6) 
					{ 
						ntcpheadlen=24; 
						pBuffer+=4; 
					} 
					//----add by chenjw 
					else if(pr1->tcppkg.HeaderLen == 8) 
					{ 
						ntcpheadlen = 32; 
						pBuffer += 12; 
					} 
*/ 
					niptcpheadlen=nipheadlen+ntcpheadlen; 
					//6.See Data 
					for(i=0;i < (nIpTcpDataLen - niptcpheadlen);i++) 
					{ 
						pr1->databuff[i] = *pBuffer++; 
					} 
					pr1->DataLen=nIpTcpDataLen-niptcpheadlen; 
#ifdef DEBUG1 
{ 
char debugtemp[6]; 
sprintf(debugtemp,"%x %x %x %x %x %x", 
		(uchar)pr1->buff[0],(uchar)pr1->buff[1], 
		(uchar)pr1->buff[2],(uchar)pr1->buff[3], 
		(uchar)pr1->buff[nIpTcpDataLen - 42], 
		(uchar)pr1->buff[nIpTcpDataLen - 41]); 
AfxMessageBox(debugtemp); 
} 
#endif 
 
					int hr=(nMacIpTcpDataLen-nIpTcpDataLen-14);			 
					pBuffer+=hr; 
 
#ifdef DEBUG1 
{ 
char debugetemp[20]; 
sprintf(debugetemp,"%d ",hr); 
AfxMessageBox("after for Data"); 
AfxMessageBox(debugetemp); 
} 
#endif		 
 
				//compute and save how many line for data 
					nRight = ((nIpTcpDataLen-niptcpheadlen+15)/16); 
					pr1->nLine = nRight; 
				}//else--end tcp 
				else  
				{ 
					//pr1->tcppkg.SrcPort = 0; 
					//pr1->tcppkg.DesPort = 0; 
					pr1->DataLen = 0; 
					pr1->nLine = 0; 
					pBuffer += (nIpTcpDataLen - 20 - 4); 
				}//else -end udp 
				 
			}//-------end tcp/udp ---add by chenjw 
			else 
			{ 
				//int nLogLinctrlLen = pl1->macpkg.NetType[0]<<8 | pl1->macpkg.NetType[1]; 
				pr1->tcppkg.SrcPort =0; 
				pr1->DataLen = 0; 
				pr1->nLine = 0; 
				pr1->ippkg.srcIP[0] = 0x00; 
				pr1->ippkg.srcIP[1] = 0x00; 
				pr1->ippkg.srcIP[2] = 0x00; 
				pr1->ippkg.srcIP[3] = 0x00; 
				pBuffer += (nMacIpTcpDataLen - 14); 
				 
			}//end else---logiclinkcontrol 
			//save right data 
			if(m_pRightDataHead == NULL) 
			{ 
				m_pRightDataHead = pr1; 
			} 
			else 
			{ 
				pr2->next = pr1; 
			} 
			pr2=pr1; 
			pr1=(pTCPIPPKG)malloc(sizeof(TCPIPPKG)); 
		}//---end else---t->s 
		 
	}//stop for(;;) 
//=================================add by chenjw 
	//which view is left or right 
	if(pl2->tcppkg.SrcPort< pr2->tcppkg.SrcPort) 
		{ 
			pTempHead = NULL; 
			pTempHead = m_pRightDataHead; 
			m_pRightDataHead = m_pLeftDataHead; 
			m_pLeftDataHead = pTempHead; 
		} 
	pl2->next=NULL; 
	pr2->next=NULL; 
} 
/////////////////////////////////////////////////////// 
/* 
 * Function: int HexToAscll() 
 * return: is number of two dismention array 
 * src Data:    0x31,       0x32,        0x33,        0x31 
 *             /   \        /   \        /   \        /   \ 
 * des Data:0x330x310x20,0x330x320x20,0x330x330x20,0x330x310x20 
 * 
 */ 
int CIrisAnalyseDoc::HexToAscll(unsigned char *des,unsigned char *src,int len) 
{ 
	int i,j; 
	unsigned char *strDes,*strSrc; 
	 
	strDes = des; 
	strSrc = src; 
	 
	for( i=0,j=1; i> 4) | 0x30) <= 0x39 ) 
		{  
			*strDes++ = (*strSrc >> 4) | 0x30; 
		} 
		else 
		{ 
			*strDes++ = (unsigned char)(((*strSrc >> 4) | 0x30) +0x27); 
		} 
 
		// From low halt byte to byte 
		if( ((*strSrc & 0x0f) | 0x30) <= 0x39 ) 
		{ 
			*strDes++ = (*strSrc & 0x0f) | 0x30; 
		} 
		else 
		{ 
			*strDes++ = (unsigned char)(((*strSrc & 0x0f) | 0x30) + 0x27); 
		} 
		if( (j%16) == 0x00)//judge 16 byte 
		{ 
			*strDes ++ = 0x00; 
		} 
		else if(j != len)// last byte is not 0x20 
		{ 
			*strDes ++ = 0x20; 
		} 
		strSrc += 1; 
	} 
	*strDes = 0x00; 
 
	return (int)((len+15)/16); 
} 
UINT CIrisAnalyseDoc::GetDataLen() 
{ 
	return m_nFileLength; 
}