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


// ARPGram.cpp: implementation of the ARPGram class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "snifferpro.h" 
#include "ARPGram.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
u_char hardware_destination[6]; 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
ARPGram::ARPGram() 
{ 
 
} 
 
ARPGram::ARPGram(const unsigned char *buf,unsigned int buflen) 
{ 
	unsigned char *pos=(unsigned char *)buf; 
	hdwaddrtype=(*pos)*0x100+(*(pos+1)); 
 
	pos+=2; 
	prtaddrtype=(*pos)*0x100+(*(pos+1)); 
 
	pos+=2; 
	hdwaddrlen=(*pos); 
 
	pos++; 
	prtaddrlen=(*pos); 
 
	pos++; 
	operation=(*pos)*0x100+(*(pos+1)); 
 
	pos+=2; 
	for(int i=0;i<6;i++){		 
		srchdwaddr[i]=BYTE(*pos); 
		pos++; 
	} 
 
	srcprtaddr=(*pos)*0x1000000+(*(pos+1))*0x10000+(*(pos+2))*0x100+(*(pos+3)); 
 
	pos+=4; 
	for(i=0;i<6;i++){ 
		desthdwaddr[i]=BYTE(*pos); 
		hardware_destination[i]=desthdwaddr[i]; 
		pos++; 
	} 
 
	destprtaddr=(*pos)*0x1000000+(*(pos+1))*0x10000+(*(pos+2))*0x100+(*(pos+3)); 
 
} 
 
ARPGram::~ARPGram() 
{ 
 
} 
 
CString ARPGram::GetSrcHdwAddr() 
{ 
	CString str; 
	str.Format("%02X:%02X:%02X:%02X:%02X:%02X",srchdwaddr[0],srchdwaddr[1],srchdwaddr[2],srchdwaddr[3],srchdwaddr[4],srchdwaddr[5]); 
	return str; 
} 
 
CString ARPGram::GetSrcPrtAddr() 
{ 
	CString str; 
	unsigned char *p; 
 
	p=(unsigned char *)&srcprtaddr; 
	str.Format("%003u.%003u.%003u.%003u",p[3],p[2],p[1],p[0]); 
	return str; 
} 
 
CString ARPGram::GetDestHdwAddr() 
{ 
	CString str; 
	str.Format("%02X:%02X:%02X:%02X:%02X:%02X",desthdwaddr[0],desthdwaddr[1],desthdwaddr[2],desthdwaddr[3],desthdwaddr[4],desthdwaddr[5]); 
	return str; 
} 
 
CString ARPGram::GetDestPrtAddr() 
{ 
	CString str; 
	unsigned char *p; 
 
	p=(unsigned char *)&destprtaddr; 
	str.Format("%003u.%003u.%003u.%003u",p[3],p[2],p[1],p[0]); 
	return str; 
} 
 
CString ARPGram::GetOperation() 
{ 
	CString str; 
	switch(this->operation){ 
	case 1: 
		str.Format("ARP Request"); 
		break; 
	case 2: 
		str.Format("ARP Reply"); 
		break; 
	default: 
		str.Format(""); 
	} 
	return str; 
} 
 
CString ARPGram::GetPrtType() 
{ 
	CString str; 
	switch(prtaddrtype){ 
	case 0x0800: 
		str.Format("IP"); 
		break; 
	default: 
		str.Format(""); 
	} 
	return str; 
}