![]() |
GetCraftedPacket() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Public Function |
Declared in: IPCrafter.h |
char * GetCraftedPacket( const CSpoofSocket* pSocket, unsigned long ulDestinationAddress, const char* pBuffer, unsigned short usBufferSize, unsigned short& usTotalSize) const;
Get the memory of a crafted packet (returns an allocated buffer with the packet)
try { //Check if the length is too big if (IpHeaderLength+(long)usBufferSize>65535) { //Report it ReportError("GetCraftedPacket","Packet can't be greater then 65k!"); //Exit return NULL; } //Header length unsigned char ucHeaderLength=IpHeaderLength; if (pSocket->HasOptions()) ucHeaderLength+=pSocket->GetOptions()->GetBufferLength(); //First construct the packet LPIpHeader lpHead=pSocket->ConstructIPHeader(pSocket->GetProtocol(), IpFragFlag_DONT_FRAG, pSocket->GetTTL(), (unsigned short)GetCurrentProcessId(), ucHeaderLength); //Set the address pSocket->SetIPHeaderAddress(lpHead, pSocket->GetSourceAddress(), ulDestinationAddress); //Now add some more options unsigned short usTotalLength; usTotalLength=ucHeaderLength+usBufferSize; //Set the header lpHead->usTotalLength=htons(usTotalLength); //Need to construct a new packet char* pNewBuf; pNewBuf=new char[usTotalLength]; //Copy two buffers memcpy(pNewBuf, lpHead, IpHeaderLength); //Do we need to copy options ? if (pSocket->HasOptions()) memcpy(pNewBuf+IpHeaderLength, pSocket->GetOptions()->GetBuffer(), pSocket->GetOptions()->GetBufferLength()); //Only if not null if (pBuffer) memcpy(pNewBuf+ucHeaderLength, pBuffer, usBufferSize); //Calculate the checksum lpHead->usChecksum=pSocket->CalculateChecksum((unsigned short*)pNewBuf, ucHeaderLength); //Alert everyone this is the final header pSocket->FinalIPHeader(lpHead); //Recopy the ip memcpy(pNewBuf, lpHead, IpHeaderLength); //Set the total size usTotalSize=usTotalLength; //Return to the user return pNewBuf; } ERROR_HANDLER_RETURN("GetCraftedPacket",NULL)
![]() |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |