![]() |
ProccessICMP() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Protected Function |
Declared in: ICMPSocket.h |
virtual BOOL ProccessICMP( const char* pBuffer);
Proccess incoming ICMP data
try { //Here we proccess the input we received //Do we have previous data? if (m_pICMPReceiveData) { //Delete it delete [] m_pICMPReceiveData; m_pICMPReceiveData=NULL; } //No user data m_usDataSize=0; //Initialize members if (!m_pIPHeader) m_pIPHeader=new IpHeader; if (!m_pICMPHeader) m_pICMPHeader=new ICMPHeader; //Create an IP header LPIpHeader lpHead; lpHead=m_pIPHeader; //Copy to buffer memcpy(lpHead, pBuffer, IpHeaderLength); //Let's check for options unsigned char ucHeaderSize; ucHeaderSize=(lpHead->ucHeaderLength_Version & 15) << 2; //Now check for total packet size unsigned short ucPacketSize; ucPacketSize=htons(lpHead->usTotalLength); //Copy data to icmp memset(m_pICMPHeader, 0, ICMPHeaderLength); //How much to copy ? unsigned short ucCopy; ucCopy=ucPacketSize-ucHeaderSize; //Save the datasize m_usDataSize=ucCopy; if (ucCopy>ICMPHeaderLength) ucCopy=ICMPHeaderLength; //Copy the ICMP header memcpy(m_pICMPHeader, pBuffer+ucHeaderSize, ucCopy); //Now save the original IP if (!m_pICMPIPHeader) m_pICMPIPHeader=new IpHeader; //Copy the data memcpy(m_pICMPIPHeader, pBuffer+ucHeaderSize+ICMP_DATA_SIZE, IpHeaderLength); //Get this header size unsigned char ucNewHeaderSize; ucNewHeaderSize=(m_pICMPIPHeader->ucHeaderLength_Version & 15) << 2; //Do we have ICMP buffer if (!(m_pICMPHeader->ucICMPType!=ICMP_Echo && m_pICMPHeader->ucICMPType!=ICMP_Echo_Reply && m_pICMPHeader->ucICMPType!=ICMP_Timestamp && m_pICMPHeader->ucICMPType!=ICMP_Timestamp_Reply && m_pICMPHeader->ucICMPType!=ICMP_Information && m_pICMPHeader->ucICMPType!=ICMP_Information_Reply && m_pICMPHeader->ucICMPType!=ICMP_Time)) { //Copy rest of data if (!m_pICMPICMPHeader) m_pICMPICMPHeader=new ICMPHeader; memcpy(m_pICMPICMPHeader, pBuffer+ucHeaderSize+ICMP_DATA_SIZE+ucNewHeaderSize, ICMP_DATA_SIZE); //Reverse it ReverseHeader(m_pICMPICMPHeader); //Do we have data to copy unsigned short usRemainingSize; usRemainingSize=ucHeaderSize+ ICMP_DATA_SIZE+ ucNewHeaderSize+ ICMP_DATA_SIZE; //Anything left? if (usRemainingSize<ucPacketSize) { //Set the size m_usDataSize=ucPacketSize-usRemainingSize; //Allocate some data m_pICMPReceiveData=new char[m_usDataSize]; //Copy it memcpy(m_pICMPReceiveData, pBuffer+usRemainingSize, m_usDataSize); } } else { //Reset the ICMP if (m_pICMPICMPHeader) memset(m_pICMPICMPHeader, 0, ICMPHeaderLength); //Do we have data to copy unsigned short usRemainingSize; usRemainingSize=ucHeaderSize+ ICMP_DATA_SIZE+ ucNewHeaderSize; //Anything left? if (usRemainingSize<ucPacketSize) { //Set the size m_usDataSize=ucPacketSize-usRemainingSize; //Allocate some data m_pICMPReceiveData=new char[m_usDataSize]; //Copy it memcpy(m_pICMPReceiveData, pBuffer+usRemainingSize, m_usDataSize); } } //Now I need to reverse the header ReverseHeader(m_pICMPHeader); //Done return TRUE; } ERROR_HANDLER_RETURN("ProccessICMP",FALSE)
![]() |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |