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


// UDPGram.cpp: implementation of the UDPGram class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "snifferpro.h" 
#include "UDPGram.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
UDPGram::UDPGram() 
{ 
 
} 
 
UDPGram::UDPGram(const unsigned char *buf,const int buflen) 
{ 
	//char *buf=new char[bufferlen]; 
	//int len=bufferlen; 
	unsigned char *pos; 
	//memcpy(buf,buffer,bufferlen); 
	 
	pos=(unsigned char *)buf; 
	srcport=(*pos)*0x100+(*(pos+1)); 
 
	pos+=2; 
	destport=(*pos)*0x100+(*(pos+1)); 
 
	pos+=2; 
	totallen=(*pos)*0x100+(*(pos+1)); 
 
	pos+=2; 
	checksum=(*pos)*0x100+(*(pos+1)); 
 
	datalen=buflen-8; 
	if(datalen>0){ 
		data=new char[datalen]; 
		memcpy(data,buf+8,datalen); 
	} 
	else 
		data=NULL; 
 
	//delete[] buf; 
} 
 
UDPGram::~UDPGram() 
{ 
	if(data!=NULL) 
		delete[] data; 
}