| CTCPSocket:: SendRaw() |

Protected Function | Declared in: TCPSocket.h

## Declaration

    virtual BOOL SendRaw(
        unsigned short usSourcePort,
        LPCSTR lpDestinationAddress,
        unsigned short usDestinationPort,
        char* buf,
        int BufLength,
        unsigned char ucFlags=0);

## Description

Send raw packet

## Function Body

    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_Options)
                iHeaderLength+=m_TCPOptions->GetBufferLength();

            //Create the header
            lpHead=ConstructTCPHeader(usSourcePort,usDestinationPort,iHeaderLength);

            if (ucFlags)
                //Set the flags
                SetHeaderFlag(lpHead,ucFlags);

            //Result
            BOOL bResult;

            //Construct diffrently if we have options
            if (m_Options)
            {
                char* oBuf;
                oBuf=new char[iHeaderLength+BufLength];

                //Copy header
                memcpy(oBuf,lpHead,TCPHeaderLength);

                //Copy options
                memcpy(oBuf+TCPHeaderLength,m_TCPOptions->GetBuffer(),m_TCPOptions->GetBufferLength());

                if (BufLength)
                    //Copy the data
                    memcpy(oBuf+TCPHeaderLength+m_TCPOptions->GetBufferLength(),buf,BufLength);

                int iTotalLength;
                iTotalLength=iHeaderLength+BufLength;

                //Checksum it
                lpHead->Checksum=CalculatePseudoChecksum(oBuf,iTotalLength,lpDestinationAddress,iTotalLength);

                //Last change to the header
                FinalTCPHeader(lpHead);

                //Recopy header
                memcpy(oBuf,lpHead,TCPHeaderLength);

                //Send the data
                bResult=CSpoofSocket::Send(lpDestinationAddress,oBuf,iHeaderLength,usDestinationPort);

                //Dispose
                delete [] oBuf;
            }
            else
            {
                //Our total length
                int iTotalLength;
                iTotalLength=iHeaderLength+BufLength;

                char* cBuf;
                cBuf=new char[iTotalLength];

                //Copy the header
                memcpy(cBuf,lpHead,iHeaderLength);

                //Copy the data
                if (BufLength)
                    //Copy the data
                    memcpy(cBuf+iHeaderLength,buf,BufLength);

                //Calculate the checksum
                lpHead->Checksum=CalculatePseudoChecksum(cBuf,iTotalLength,lpDestinationAddress,iTotalLength);

                //Last change to the header
                FinalTCPHeader(lpHead);

                //Copy the header
                memcpy(cBuf,lpHead,iHeaderLength);

                //Send the data
                bResult=CSpoofSocket::Send(lpDestinationAddress,cBuf,iTotalLength,usDestinationPort);

                //Delete the buffer
                delete [] cBuf;
            }

            //Set the last error
            SetLastError("Connect");

            //Dispose the header
            delete lpHead;

            return bResult;
        }
        else
        {
            ReportError("SendRaw","Packet not in raw mode!");
            return FALSE;
        }
    }
    ERROR_HANDLER_RETURN("SendRaw",FALSE)

## See Also

Class Overview | CSpoofSocket | Hierarchy Chart

This web site was generated using Surveyor V4.50.811.1. Click here for more information. | Site content copyright © 2001 Barak Weichselbaum. See the About page for additional notices. This page last updated: 27 Jun 2001.