![]() |
SendRaw() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Protected Function |
Declared in: TCPSocket.h |
virtual int SendRaw( unsigned short usSourcePort, IP aDestinationAddress, unsigned short usDestinationPort, const char* pBuffer, unsigned long ulBufferLength, unsigned char ucFlags=0);
Send raw packet Positive - The number of bytes received. Zero - Socket has been closed. Negative - Error
try { //Quit if not ok if (!CheckSocketValid()) return FALSE; if (IsRaw()) { //Let's try our first attack LPTCPHeader lpHead; //Header length int iHeaderLength; iHeaderLength=TCPHeaderLength; //If we have TCP options if (m_bOptions) iHeaderLength+=m_pTCPOptions->GetBufferLength(); //Create the header lpHead=ConstructTCPHeader(usSourcePort, usDestinationPort, iHeaderLength); //Protect the header std::auto_ptr<TCPHeader> pProtection(lpHead); //Set the flags if (ucFlags) //Set the flags SetHeaderFlag(lpHead,ucFlags); //Result int iResult; //Construct diffrently if we have options if (m_bOptions) { //Allocate the data char* pOptionBuffer; pOptionBuffer=new char[iHeaderLength+ulBufferLength]; //Protect the buffer CArray_ptr<char> pBufferProtection(pOptionBuffer); //Copy header memcpy(pOptionBuffer, lpHead, TCPHeaderLength); //Copy options memcpy(pOptionBuffer+TCPHeaderLength, m_pTCPOptions->GetBuffer(), m_pTCPOptions->GetBufferLength()); //Do we have the buffer if (ulBufferLength) //Copy the data memcpy(pOptionBuffer+ TCPHeaderLength+ m_pTCPOptions->GetBufferLength(), pBuffer, ulBufferLength); //Calculate the total length int iTotalLength; iTotalLength=iHeaderLength+ulBufferLength; //Change the header lpHead->ucDataOffset=(iTotalLength >> 2) << 4; //Checksum it lpHead->usChecksum=CalculatePseudoChecksum(pOptionBuffer, iTotalLength, aDestinationAddress, iTotalLength); //Last change to the header FinalTCPHeader(lpHead); //Recopy header memcpy(pOptionBuffer, lpHead, TCPHeaderLength); //Send the data iResult=CSpoofSocket::Send(aDestinationAddress, pOptionBuffer, iHeaderLength, usDestinationPort); } else { //Our total length unsigned long ulTotalLength; ulTotalLength=iHeaderLength+ulBufferLength; //Allocate the buffer char* pNewBuffer; pNewBuffer=new char[ulTotalLength]; //Protect the buffer CArray_ptr<char> pBufferProtection(pNewBuffer); //Copy the header memcpy(pNewBuffer, lpHead, ulTotalLength); //Copy the data if (ulBufferLength) //Copy the data memcpy(pNewBuffer+iHeaderLength, pBuffer, ulBufferLength); //Calculate the checksum lpHead->usChecksum=CalculatePseudoChecksum(pNewBuffer, ulTotalLength, aDestinationAddress, ulTotalLength); //Last change to the header FinalTCPHeader(lpHead); //Copy the header memcpy(pNewBuffer, lpHead, iHeaderLength); //Send the data iResult=CSpoofSocket::Send(aDestinationAddress, pNewBuffer, ulTotalLength, usDestinationPort); } //Set the last error SetLastError("Connect"); //Exit return iResult; } else { //Report it ReportError("SendRaw","Packet not in raw mode!"); //Exit return GetErrorCode(); } } ERROR_HANDLER_RETURN("SendRaw",GetErrorCode())
![]() |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |