www.pudn.com > SnifferPro.rar > SinPackView.cpp


// SinPackView.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "snifferpro.h" 
#include "SinPackView.h" 
#include "MainFrm.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CSinPackView 
 
IMPLEMENT_DYNCREATE(CSinPackView, CTreeView) 
 
CSinPackView::CSinPackView() 
{ 
	ip=NULL; 
	ether=NULL; 
	tcp=NULL; 
	udp=NULL; 
	icmp=NULL; 
	arp=NULL; 
	rarp=NULL; 
} 
 
CSinPackView::~CSinPackView() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CSinPackView, CTreeView) 
	//{{AFX_MSG_MAP(CSinPackView) 
	ON_MESSAGE(WM_MESSAGE_PACKET_SELECT,OnPacketSelect) 
	ON_NOTIFY_REFLECT(NM_CLICK, OnClick) 
	ON_NOTIFY_REFLECT(TVN_SELCHANGING, OnSelchanging) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSinPackView drawing 
 
void CSinPackView::OnDraw(CDC* pDC) 
{ 
	CDocument* pDoc = GetDocument(); 
	// TODO: add draw code here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CSinPackView diagnostics 
 
#ifdef _DEBUG 
void CSinPackView::AssertValid() const 
{ 
	CTreeView::AssertValid(); 
} 
 
void CSinPackView::Dump(CDumpContext& dc) const 
{ 
	CTreeView::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CSinPackView message handlers 
 
void CSinPackView::OnInitialUpdate()  
{ 
	CTreeView::OnInitialUpdate(); 
	 
	// TODO: Add your specialized code here and/or call the base class 
	((CMainFrame *)AfxGetApp()->GetMainWnd())->sinPackView=this; 
	CTreeCtrl &ctrl=this->GetTreeCtrl(); 
	DWORD m_dwstyle = ::GetWindowLong(ctrl.m_hWnd,GWL_STYLE); 
	m_dwstyle |= TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT; 
	::SetWindowLong(ctrl.m_hWnd,GWL_STYLE,m_dwstyle); 
} 
 
void CSinPackView::OnPacketSelect(const struct pcap_pkthdr *pkt_header, const u_char *pkt_data) 
{ 
	//清空上次残留信息 
	if(ip!=NULL){ 
		delete ip; 
		ip=NULL; 
	} 
	if(ether!=NULL){ 
		delete ether; 
		ether=NULL; 
	} 
	if(tcp!=NULL){ 
		delete tcp; 
		tcp=NULL; 
	} 
	if(udp!=NULL){ 
		delete udp; 
		udp=NULL; 
	} 
	if(icmp!=NULL){ 
		delete icmp; 
		icmp=NULL; 
	} 
	if(arp!=NULL){ 
		delete arp; 
		arp=NULL; 
	} 
	if(rarp!=NULL){ 
		delete rarp; 
		rarp=NULL; 
	} 
 
	CTreeCtrl &ctrl=this->GetTreeCtrl(); 
	ctrl.DeleteAllItems(); 
 
	 
	//Init for Ether 解析以太帧 
	ether=new EtherHead(pkt_data,14);	 
	CString strmactype; 
	strmactype.Format("%d",ether->type); 
	HTREEITEM macdest=ctrl.InsertItem("Mac Destination Address:  "+ether->GetMacDestAddr(),0); 
	HTREEITEM macsrc=ctrl.InsertItem("Mac Source Address:  "+ether->GetMacSrcAddr(),0); 
	HTREEITEM mactype=ctrl.InsertItem("Mac Frame Type: "+strmactype+"  "+ether->GetType(),0); 
	HTREEITEM macdata=ctrl.InsertItem("Mac Data:",0); 
 
	//Init for IP  
	if(ether->type==0x0800){ 
		ip=new IPGram(pkt_data+14,pkt_header->len); 
		CString stripversion; 
		CString stripIHL; 
		CString stripprecedence; 
		CString stripdelay; 
		CString stripthroughtput; 
		CString stripreliability; 
		CString stripservicetype; 
		CString striptotallen; 
		CString stripid; 
		CString stripDF; 
		CString stripMF; 
		CString stripfragoffset; 
		CString stripTTL; 
		CString stripproto; 
		CString stripchecksum; 
		CString stripdatalen; 
		CString stripopt; 
		stripversion.Format("%d",ip->version); 
		stripIHL.Format("%d",ip->IHL*4); 
		stripservicetype.Format("%d",ip->servicetype); 
		stripprecedence.Format("%d",ip->precedence); 
		striptotallen.Format("%d",ip->totallen); 
		stripid.Format("%d",ip->identification); 
		stripopt.Format("%d",ip->optlen); 
		if (ip->DF) 
			stripDF.Format("True"); 
		else 
			stripDF.Format("False"); 
		if (ip->MF) 
			stripMF.Format("True"); 
		else 
			stripMF.Format("False"); 
		if (ip->delay) 
			stripdelay.Format("True"); 
		else 
			stripdelay.Format("False"); 
		if (ip->throughtput) 
			stripthroughtput.Format("True"); 
		else 
			stripthroughtput.Format("False"); 
		if (ip->reliability) 
			stripreliability.Format("True"); 
		else 
			stripreliability.Format("False"); 
		stripfragoffset.Format("%d",ip->fragoffset); 
		stripTTL.Format("%d",ip->TTL); 
		stripproto.Format("%d",ip->protocol); 
		stripchecksum.Format("0x%X",ip->checksum); 
		stripdatalen.Format("%d",ip->datalen); 
		HTREEITEM ipverion=ctrl.InsertItem("IP Version:  "+stripversion,macdata); 
		HTREEITEM ipIHL=ctrl.InsertItem("Length of IP Head :  "+stripIHL+" Byte",macdata); 
		HTREEITEM ipservetype=ctrl.InsertItem("Service Type:  "+stripservicetype,macdata); 
		HTREEITEM ipprecedence=ctrl.InsertItem("Precedence:  "+stripprecedence,macdata); 
		HTREEITEM ipdelay=ctrl.InsertItem("Delay:  "+stripdelay,ipprecedence); 
		HTREEITEM ipthroughtput=ctrl.InsertItem("Throughtput:  "+stripthroughtput,ipprecedence); 
		HTREEITEM ipreliability=ctrl.InsertItem("Reliability:  "+stripreliability,ipprecedence); 
		HTREEITEM iptotallen=ctrl.InsertItem("Total Length:  "+striptotallen+" Byte",macdata); 
		HTREEITEM ipid=ctrl.InsertItem("IP Identification:  "+stripid,macdata); 
		HTREEITEM ipDF=ctrl.InsertItem("DF:  "+stripDF,macdata); 
		HTREEITEM ipMF=ctrl.InsertItem("MF:  "+stripMF,macdata); 
		HTREEITEM ipfragoffset=ctrl.InsertItem("Fragment Offset:  "+stripfragoffset,macdata); 
		HTREEITEM ipTTL=ctrl.InsertItem("Time to Live:  "+stripTTL+" Second",macdata); 
		HTREEITEM ipproto=ctrl.InsertItem("IP Protocol: "+stripproto+"  "+ip->GetService(),macdata); 
		HTREEITEM ipchecksum=ctrl.InsertItem("IP Header Check Sum:  "+stripchecksum,macdata); 
		HTREEITEM ipsrc=ctrl.InsertItem("IP Source Address:  "+ip->GetSrcAddr(),macdata); 
		HTREEITEM ipdest=ctrl.InsertItem("IP Destination Address:  "+ip->GetDestAddr(),macdata); 
		HTREEITEM ipopt=ctrl.InsertItem("IP Options:  "+stripopt+" Byte",macdata); 
		HTREEITEM ipdata=ctrl.InsertItem("IP Data:  "+stripdatalen+" Byte",macdata); 
	 
		if(ip->protocol==6){//TCP 
			tcp=new TCPGram(ip->data,ip->datalen); 
			CString strtcpsrcport; 
			CString strtcpdestport; 
			CString strtcpseq; 
			CString strtcpack; 
			CString strtcpheadlen; 
			CString strtcpURG; 
			CString strtcpACK; 
			CString strtcpPSH; 
			CString strtcpRST; 
			CString strtcpSYN; 
			CString strtcpFIN; 
			CString strtcpwinsize; 
			CString strtcpchecksum; 
			CString strtcpurgpos; 
			CString strtcpdatalen; 
			CString strtcpopt; 
			strtcpsrcport.Format("%d",tcp->srcport); 
			strtcpdestport.Format("%d",tcp->destport); 
			strtcpseq.Format("%u",tcp->seqnum); 
			strtcpack.Format("%u",tcp->acknum); 
			strtcpheadlen.Format("%d",tcp->headlen*4); 
			if(tcp->URG) 
				strtcpURG.Format("True"); 
			else 
				strtcpURG.Format("False"); 
			if(tcp->ACK) 
				strtcpACK.Format("True"); 
			else 
				strtcpACK.Format("False"); 
			if(tcp->PSH) 
				strtcpPSH.Format("True"); 
			else 
				strtcpPSH.Format("False"); 
			if(tcp->RST) 
				strtcpRST.Format("True"); 
			else 
				strtcpRST.Format("False"); 
			if(tcp->SYN) 
				strtcpSYN.Format("True"); 
			else 
				strtcpSYN.Format("False"); 
			if(tcp->FIN) 
				strtcpFIN.Format("True"); 
			else 
				strtcpFIN.Format("False"); 
			strtcpwinsize.Format("%d",tcp->windowsize); 
			strtcpchecksum.Format("0x%X",tcp->checksum); 
			strtcpurgpos.Format("%d",tcp->urgpos); 
			strtcpdatalen.Format("%d",tcp->datalen); 
			strtcpopt.Format("%d",tcp->optlen); 
			HTREEITEM tcpsrc=ctrl.InsertItem("TCP Source Port:  "+strtcpsrcport,ipdata); 
			HTREEITEM tcpdest=ctrl.InsertItem("TCP Destination Port:  "+strtcpdestport,ipdata); 
			HTREEITEM tcpseq=ctrl.InsertItem("Sequence Num:  "+strtcpseq,ipdata); 
			HTREEITEM tcpack=ctrl.InsertItem("Acknowledgement Num:  "+strtcpack,ipdata); 
			HTREEITEM tcpheadlen=ctrl.InsertItem("Length of TCP Head:  "+strtcpheadlen+" Byte",ipdata); 
			HTREEITEM tcpflag=ctrl.InsertItem("TCP Flags:",ipdata); 
			HTREEITEM tcpURG=ctrl.InsertItem("URG:  "+strtcpURG,tcpflag); 
			HTREEITEM tcpACK=ctrl.InsertItem("ACK:  "+strtcpACK,tcpflag); 
			HTREEITEM tcpPSH=ctrl.InsertItem("PSH:  "+strtcpPSH,tcpflag); 
			HTREEITEM tcpRST=ctrl.InsertItem("RST:  "+strtcpRST,tcpflag); 
			HTREEITEM tcpSYN=ctrl.InsertItem("SYN:  "+strtcpSYN,tcpflag); 
			HTREEITEM tcpFIN=ctrl.InsertItem("FIN:  "+strtcpFIN,tcpflag); 
			HTREEITEM tcpwinsize=ctrl.InsertItem("Window Size:  "+strtcpwinsize+" Byte",ipdata); 
			HTREEITEM tcpchecksum=ctrl.InsertItem("TCP Header Check Sum:  "+strtcpchecksum,ipdata); 
			HTREEITEM tcpurgpos=ctrl.InsertItem("Urgent Pointer:  "+strtcpurgpos,ipdata); 
			HTREEITEM tcpopt=ctrl.InsertItem("TCP Options:  "+strtcpopt+" Byte",ipdata); 
			HTREEITEM tcpdata=ctrl.InsertItem("TCP Data:  "+strtcpdatalen+" Byte",ipdata); 
			ctrl.Expand(tcpflag,TVE_EXPAND); 
		}//Init for TCP 
		 
		else if(ip->protocol==17){//Init for UDP 
			udp=new UDPGram(ip->data,ip->datalen); 
			CString strudpsrcport; 
			CString strudpdestport; 
			CString strudplen; 
			CString strudpchecksum; 
			CString strudpdatalen; 
			strudpsrcport.Format("%u",udp->srcport); 
			strudpdestport.Format("%u",udp->destport); 
			strudplen.Format("%u",udp->totallen); 
			strudpchecksum.Format("%X",udp->checksum); 
			strudpdatalen.Format("%u",udp->datalen); 
			HTREEITEM udpsrcport=ctrl.InsertItem("UDP Source Port:  "+strudpsrcport,ipdata); 
			HTREEITEM udpdestport=ctrl.InsertItem("UDP Destination Port:  "+strudpdestport,ipdata); 
			HTREEITEM udplen=ctrl.InsertItem("UDP Length:  "+strudplen+" Byte",ipdata); 
			HTREEITEM udpchecksum=ctrl.InsertItem("UDP Header Check Sum:  "+strudpchecksum,ipdata); 
			HTREEITEM udpdata=ctrl.InsertItem("UDP Data:  "+strudpdatalen+" Byte",ipdata); 
		}//Init for UDP 
 
		else if(ip->protocol==1){//Init for ICMP 
			icmp=new ICMPGram(ip->data,ip->datalen); 
			CString stricmptype; 
			CString stricmpcode; 
			CString stricmpchecksum; 
			CString stricmpdatalen; 
			CString stricmptypevalue; 
			CString stricmpcodevalue; 
			CString stricmpid; 
			CString stricmpseq; 
			CString stricmpinittime; 
			CString stricmpreceivetime; 
			CString stricmpsendtime; 
 
			icmp->GetType(stricmptype,stricmpcode); 
			stricmpchecksum.Format("0x%X",icmp->checksum); 
			stricmpdatalen.Format("%d",icmp->datalen); 
			stricmptypevalue.Format("%d",icmp->type); 
			stricmpcodevalue.Format("%d",icmp->code); 
			HTREEITEM icmptype=ctrl.InsertItem("ICMP Type: "+stricmptypevalue+"  "+stricmptype,ipdata); 
			HTREEITEM icmpcode=ctrl.InsertItem("ICMP Code: "+stricmpcodevalue+"  "+stricmpcode,ipdata); 
			HTREEITEM icmpchecksum=ctrl.InsertItem("ICMP Check Sum:  "+stricmpchecksum,ipdata); 
			switch(icmp->type){ 
			case 3: 
				//stricmpid.Format("0"); 
				//stricmpseq.Format("0"); 
				break; 
			case 5: 
				stricmpid.Format("%u",icmp->identification); 
				stricmpseq.Format("%u",icmp->sequence); 
				ctrl.InsertItem("ICMP Identification:  "+stricmpid,ipdata);  
				ctrl.InsertItem("ICMP Sequence:  "+stricmpseq,ipdata); 
				ctrl.InsertItem("GateWay:  "+icmp->GetGateWay(),ipdata); 
				break; 
			case 8: 
				stricmpid.Format("%u",icmp->identification); 
				stricmpseq.Format("%u",icmp->sequence); 
				ctrl.InsertItem("ICMP Identification:  "+stricmpid,ipdata);  
				ctrl.InsertItem("ICMP Sequence:  "+stricmpseq,ipdata); 
				break; 
			case 0: 
				stricmpid.Format("%u",icmp->identification); 
				stricmpseq.Format("%u",icmp->sequence); 
				ctrl.InsertItem("ICMP Identification:  "+stricmpid,ipdata);  
				ctrl.InsertItem("ICMP Sequence:  "+stricmpseq,ipdata); 
				break; 
			case 13: 
				stricmpid.Format("%u",icmp->identification); 
				stricmpseq.Format("%u",icmp->sequence); 
				stricmpinittime.Format("%u",icmp->inittime); 
				stricmpreceivetime.Format("%u",icmp->receivetime); 
				stricmpsendtime.Format("%d",icmp->sendtime); 
				ctrl.InsertItem("ICMP Identification:  "+stricmpid,ipdata);  
				ctrl.InsertItem("ICMP Sequence:  "+stricmpseq,ipdata); 
				ctrl.InsertItem("Initial Time:  "+stricmpinittime,ipdata); 
				ctrl.InsertItem("Receiving Time:  "+stricmpreceivetime,ipdata); 
				ctrl.InsertItem("Sending Time:  "+stricmpsendtime,ipdata); 
				break; 
			case 14: 
				stricmpid.Format("%u",icmp->identification); 
				stricmpseq.Format("%u",icmp->sequence); 
				stricmpinittime.Format("%u",icmp->inittime); 
				stricmpreceivetime.Format("%u",icmp->receivetime); 
				stricmpsendtime.Format("%d",icmp->sendtime); 
				ctrl.InsertItem("ICMP Identification:  "+stricmpid,ipdata);  
				ctrl.InsertItem("ICMP Sequence:  "+stricmpseq,ipdata); 
				ctrl.InsertItem("Initial Time:  "+stricmpinittime,ipdata); 
				ctrl.InsertItem("Receiving Time:  "+stricmpreceivetime,ipdata); 
				ctrl.InsertItem("Sending Time:  "+stricmpsendtime,ipdata); 
				break; 
			case 17: 
				stricmpid.Format("%u",icmp->identification); 
				stricmpseq.Format("%u",icmp->sequence); 
				ctrl.InsertItem("ICMP Identification:  "+stricmpid,ipdata);  
				ctrl.InsertItem("ICMP Sequence:  "+stricmpseq,ipdata); 
				ctrl.InsertItem("Address Mask:  "+icmp->GetAddrMask(),ipdata); 
				break; 
			case 18: 
				stricmpid.Format("%u",icmp->identification); 
				stricmpseq.Format("%u",icmp->sequence); 
				ctrl.InsertItem("ICMP Identification:  "+stricmpid,ipdata);  
				ctrl.InsertItem("ICMP Sequence:  "+stricmpseq,ipdata); 
				ctrl.InsertItem("Address Mask:  "+icmp->GetAddrMask(),ipdata); 
				break; 
			} 
			HTREEITEM icmpdata=ctrl.InsertItem("ICMP Data:  "+stricmpdatalen+" Byte",ipdata); 
		}//Init for ICMP 
		ctrl.Expand(ipprecedence,TVE_EXPAND); 
		ctrl.Expand(ipdata,TVE_EXPAND); 
	}//Init for IP 
 
	//Init for ARP  
	else if(ether->type==0x0806){ 
		arp=new ARPGram(pkt_data+14,pkt_header->len-14); 
		CString strarphdwtype; 
		CString strarpprttype; 
		CString strarphdwaddrlen; 
		CString strarpprtaddrlen; 
		strarphdwtype.Format("%u",arp->hdwaddrtype); 
		strarpprttype.Format("%u",arp->prtaddrtype); 
		strarphdwaddrlen.Format("%u",arp->hdwaddrlen); 
		strarpprtaddrlen.Format("%u",arp->prtaddrlen); 
		HTREEITEM arphdwtype=ctrl.InsertItem("Hardware Address Type:  "+strarphdwtype,macdata); 
		HTREEITEM arpprttype=ctrl.InsertItem("Protocol Address Type: "+strarpprttype+"  "+arp->GetPrtType(),macdata); 
		HTREEITEM arphdwaddrlen=ctrl.InsertItem("Hardware Address Length:  "+strarphdwaddrlen,macdata); 
		HTREEITEM arpprtaddrlen=ctrl.InsertItem("Protocol Address Length:  "+strarpprtaddrlen,macdata); 
		HTREEITEM arptype=ctrl.InsertItem("Operation Type:  "+arp->GetOperation(),macdata); 
		HTREEITEM arpsrchdwaddr=ctrl.InsertItem("Source Hardware Address:  "+arp->GetSrcHdwAddr(),macdata); 
		HTREEITEM arpsrcprtaddr=ctrl.InsertItem("Source Protocol Address:  "+arp->GetSrcPrtAddr(),macdata); 
		HTREEITEM arpdesthdwaddr=ctrl.InsertItem("Destination Hardware Address:  "+arp->GetDestHdwAddr(),macdata); 
		HTREEITEM arpdestprtaddr=ctrl.InsertItem("Destination Protocol Address:  "+arp->GetDestPrtAddr(),macdata); 
	}//Init for ARP 
 
	//Init for RARP 
	else if(ether->type==0x8035){ 
		rarp=new RARPGram(pkt_data+14,pkt_header->len-14); 
		CString strrarphdwtype; 
		CString strrarpprttype; 
		CString strrarphdwaddrlen; 
		CString strrarpprtaddrlen; 
		strrarphdwtype.Format("%u",rarp->hdwaddrtype); 
		strrarpprttype.Format("%u",rarp->prtaddrtype); 
		strrarphdwaddrlen.Format("%u",rarp->hdwaddrlen); 
		strrarpprtaddrlen.Format("%u",rarp->prtaddrlen); 
		HTREEITEM rarphdwtype=ctrl.InsertItem("Hardware Address Type:  "+strrarphdwtype,macdata); 
		HTREEITEM rarpprttype=ctrl.InsertItem("Protocol Address Type:  "+strrarpprttype+"  "+arp->GetPrtType(),macdata); 
		HTREEITEM rarphdwaddrlen=ctrl.InsertItem("Hardware Address Length:  "+strrarphdwaddrlen,macdata); 
		HTREEITEM rarpprtaddrlen=ctrl.InsertItem("Hardware Address Length:  "+strrarpprtaddrlen,macdata); 
		HTREEITEM rarptype=ctrl.InsertItem("Hardware Address Type:  "+rarp->GetOperation(),macdata); 
		HTREEITEM rarpsrchdwaddr=ctrl.InsertItem("Source Hardware Address:  "+rarp->GetSrcHdwAddr(),macdata); 
		HTREEITEM rarpsrcprtaddr=ctrl.InsertItem("Source Protocol Address:  "+rarp->GetSrcPrtAddr(),macdata); 
		HTREEITEM rarpdesthdwaddr=ctrl.InsertItem("Destination Hardware Address:  "+rarp->GetDestHdwAddr(),macdata); 
		HTREEITEM rarpdestprtaddr=ctrl.InsertItem("Destination Protocol Address:  "+rarp->GetDestPrtAddr(),macdata); 
	}//Init for RARP 
	ctrl.Expand(macdata,TVE_EXPAND); 
	ctrl.SetScrollPos(SB_VERT,0); 
} 
 
void CSinPackView::OnClick(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	*pResult = 0; 
} 
 
Founder CSinPackView::GetFounder(CString name) 
{ 
	Founder founder; 
	founder.start=0; 
	founder.len=0; 
 
	//MAC 
	if(name.Find("Mac Source",0)>=0){//根据所选的字段名,进行定位,以便通知CStcView显示,下同 
		founder.start=6;//表示从跳过报文的前6个字节,然后开始,共6字节 
		founder.len=6; 
		return founder; 
	} 
	else if(name.Find("Mac Destination",0)>=0){ 
		founder.start=0; 
		founder.len=6; 
		return founder; 
	} 
	else if(name.Find("Mac Frame Type",0)>=0){ 
		founder.start=12; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Mac Data",0)>=0){ 
		founder.start=14; 
		if(ether->type==0x0800) 
			founder.len=ip->datalen+ip->IHL*4; 
		else 
			founder.len=28; 
		return founder; 
	} 
	//IP 
	else if(name.Find("IP Version",0)>=0){ 
		founder.start=14; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Length of IP Head",0)>=0){ 
		founder.start=14; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Service Type",0)>=0){ 
		founder.start=15; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Total Length",0)>=0){ 
		founder.start=16; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("IP Identification",0)>=0){ 
		founder.start=18; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Precedence")>=0){ 
		founder.start=15; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Delay")>=0){ 
		founder.start=15; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Throughtput")>=0){ 
		founder.start=15; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Reliability")>=0){ 
		founder.start=15; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("DF",0)>=0){ 
		founder.start=20; 
		founder.len=1; 
	} 
	else if(name.Find("MF",0)>=0){ 
		founder.start=20; 
		founder.len=1; 
	} 
	else if(name.Find("Fragment Offset",0)>=0){ 
		founder.start=20; 
		founder.len=2; 
	} 
	else if(name.Find("Time to Live",0)>=0){ 
		founder.start=22; 
		founder.len=1; 
	} 
	else if(name.Find("IP Protocol",0)>=0){ 
		founder.start=23; 
		founder.len=1; 
	} 
	else if(name.Find("IP Header Check Sum",0)>=0){ 
		founder.start=24; 
		founder.len=2; 
	} 
	else if(name.Find("IP Source",0)>=0){ 
		founder.start=26; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("IP Destination",0)>=0){ 
		founder.start=30; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("IP Options",0)>=0){ 
		founder.start=14+20; 
		founder.len=ip->optlen; 
		return founder; 
	} 
	else if(name.Find("IP Data",0)>=0){ 
		founder.start=14+ip->IHL*4; 
		founder.len=ip->datalen; 
		return founder; 
	} 
	//TCP 
	else if(name.Find("TCP Source",0)>=0){ 
		founder.start=14+ip->IHL*4; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("TCP Destination",0)>=0){ 
		founder.start=14+ip->IHL*4+2; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Sequence",0)>=0){ 
		founder.start=14+ip->IHL*4+4; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("Acknowledgement",0)>=0){ 
		founder.start=14+ip->IHL*4+8; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("Length of TCP Head",0)>=0){ 
		founder.start=14+ip->IHL*4+12; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("TCP Flags",0)>=0){ 
		founder.start=14+ip->IHL*4+13; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("URG",0)>=0){ 
		founder.start=14+ip->IHL*4+13; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("ACK",0)>=0){ 
		founder.start=14+ip->IHL*4+13; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("PSH",0)>=0){ 
		founder.start=14+ip->IHL*4+13; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("RST",0)>=0){ 
		founder.start=14+ip->IHL*4+13; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("SYN",0)>=0){ 
		founder.start=14+ip->IHL*4+13; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("FIN",0)>=0){ 
		founder.start=14+ip->IHL*4+13; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Window Size",0)>=0){ 
		founder.start=14+ip->IHL*4+14; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Urgent Pointer",0)>=0){ 
		founder.start=14+ip->IHL*4+18; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("TCP Header Check Sum",0)>=0){ 
		founder.start=14+ip->IHL*4+16; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("TCP Options",0)>=0){ 
		founder.start=14+ip->IHL*4+20; 
		founder.len=tcp->optlen; 
		return founder; 
	} 
	else if(name.Find("TCP Data",0)>=0){ 
		founder.start=14+ip->IHL*4+tcp->headlen*4; 
		founder.len=tcp->datalen; 
		return founder; 
	} 
	//UDP 
	else if(name.Find("UDP Source",0)>=0){ 
		founder.start=14+ip->IHL*4; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("UDP Destination",0)>=0){ 
		founder.start=14+ip->IHL*4+2; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("UDP Length",0)>=0){ 
		founder.start=14+ip->IHL*4+4; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("UDP Header Check Sum",0)>=0){ 
		founder.start=14+ip->IHL*4+6; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("UDP Data",0)>=0){ 
		founder.start=14+ip->IHL*4+8; 
		founder.len=udp->datalen; 
		return founder; 
	} 
	//ICMP 
	else if(name.Find("ICMP Type",0)>=0){ 
		founder.start=14+ip->IHL*4; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("ICMP Code",0)>=0){ 
		founder.start=14+ip->IHL*4+1; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("ICMP Check Sum",0)>=0){ 
		founder.start=14+ip->IHL*4+2; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("ICMP Identification",0)>=0){ 
		founder.start=14+ip->IHL*4+4; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("ICMP Sequence",0)>=0){ 
		founder.start=14+ip->IHL*4+6; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Initial Time",0)>=0){ 
		founder.start=14+ip->IHL*4+8; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("Receiving Time",0)>=0){ 
		founder.start=14+ip->IHL*4+12; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("Sending Time",0)>=0){ 
		founder.start=14+ip->IHL*4+16; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Address Mask",0)>=0){ 
		founder.start=14+ip->IHL*4+8; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("Gateway",0)>=0){ 
		founder.start=14+ip->IHL*4+4; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("ICMP Data",0)>=0){ 
		founder.start=14+ip->IHL*4+4; 
		founder.len=icmp->datalen; 
		return founder; 
	} 
	//ARP or RARP 
	else if(name.Find("Hardware Address Type",0)>=0){ 
		founder.start=14; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Protocol Address Type",0)>=0){ 
		founder.start=14+2; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Hardware Address Length",0)>=0){ 
		founder.start=14+4; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Protocol Address Length",0)>=0){ 
		founder.start=14+5; 
		founder.len=1; 
		return founder; 
	} 
	else if(name.Find("Operation",0)>=0){ 
		founder.start=14+6; 
		founder.len=2; 
		return founder; 
	} 
	else if(name.Find("Source Hardware Address",0)>=0){ 
		founder.start=14+8; 
		founder.len=6; 
		return founder; 
	} 
	else if(name.Find("Source Protocol Address",0)>=0){ 
		founder.start=14+14; 
		founder.len=4; 
		return founder; 
	} 
	else if(name.Find("Destination Hardware Address",0)>=0){ 
		founder.start=14+18; 
		founder.len=6; 
		return founder; 
	} 
	else if(name.Find("Destination Protocol Address",0)>=0){ 
		founder.start=14+24; 
		founder.len=4; 
		return founder; 
	} 
 
	return founder; 
} 
 
 
void CSinPackView::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; 
	// TODO: Add your control notification handler code here 
	CTreeCtrl &ctrl=this->GetTreeCtrl(); 
	HTREEITEM h=pNMTreeView->itemNew.hItem; 
	CString name=ctrl.GetItemText(h); 
	Founder founder=this->GetFounder(name); 
	unsigned int start,len;	 
	start=founder.start; 
	len=founder.len; 
	::PostMessage(*((CMainFrame *)AfxGetApp()->GetMainWnd())->stcView,WM_MESSAGE_PACKET_SPECIFY,(WPARAM)start,(LPARAM)len); 
	*pResult = 0; 
}