Class CUDPSocket::
Send()
Base ClassesConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: SendNext page: Send    Show member index
Public Function Declared in:
UDPSocket.h

'Declaration' icon -- Shortcut to top of page. Declaration

virtual BOOL Send(
    unsigned short usSourcePort,
    IP aDestinationAddress,
    unsigned short usDestinationPort,
    const char* pBuffer,
    unsigned short usBufferLength);

'Description' icon -- Shortcut to top of page. Description

Send UDP datagrams usSourcePort - Applicatable for raw sockets only Return value: Positive - The number of bytes received. Zero - Socket has been closed. Negative - Error

'Function Body' icon -- Shortcut to top of page. Function Body

try
{
    //Quit if not ok
    if (!CheckSocketValid())
        return FALSE;

    //Are we raw?
    if (IsRaw())
    {
        //We can construct the UDP here
        UDPHeader aHeader;

        //Set the ports
        aHeader.usSourcePort=htons(usSourcePort);
        aHeader.usDestinationPort=htons(usDestinationPort);

        //Set the length
        aHeader.usLength=htons(UDPHeaderLength);

        //Check sum
        aHeader.usChecksum=0;

        //Result flag
        int iResult;

        //Do we have a buffer ?
        if (usBufferLength)
        {
            //Create the buffer
            unsigned long ulTotalLength;
            ulTotalLength=UDPHeaderLength+usBufferLength;

            //Allocatet the buffer
            char* pNewBuffer;
            pNewBuffer=new char[ulTotalLength];

            //Protect the buffer
            CArray_ptr<char> pProtection(pNewBuffer);

            //Set the length
            aHeader.usLength=htons(ulTotalLength);

            //Copy the UDP header
            memcpy(pNewBuffer,
                   &aHeader,
                   UDPHeaderLength);

            //Copy the data
            memcpy(pNewBuffer+UDPHeaderLength,
                   pBuffer,
                   usBufferLength);

            //Update it
            aHeader.usChecksum=CalculatePseudoChecksum(pNewBuffer,
                                                       ulTotalLength,
                                                       aDestinationAddress,
                                                       ulTotalLength);

            //Set the new checksum (if applicateable)
            FinalUDPHeader(&aHeader);

            //Recopy it
            memcpy(pNewBuffer,
                   &aHeader,
                   UDPHeaderLength);

            //Send it
            iResult=CSpoofSocket::Send(aDestinationAddress,
                                       pNewBuffer,
                                       ulTotalLength,
                                       usDestinationPort);
        }
        else
        {
            //Update it
            aHeader.usChecksum=CalculatePseudoChecksum((char*)&aHeader,
                                                       UDPHeaderLength,
                                                       aDestinationAddress,
                                                       UDPHeaderLength);

            //Set the new checksum (if applicateable)
            FinalUDPHeader(&aHeader);

            //Send it
            iResult=CSpoofSocket::Send(aDestinationAddress,
                                       (char*)&aHeader,
                                       UDPHeaderLength,
                                       usDestinationPort);
        }

        //Done
        return iResult;
    }
    else
        //Try a regular send
        return CSpoofSocket::Send(aDestinationAddress,
                                  pBuffer,
                                  usBufferLength,
                                  usDestinationPort);
}
ERROR_HANDLER_RETURN("Send",FALSE)

'See Also' icon -- Shortcut to top of page. See Also

Class Overview Class Overview  |  Public base class CSpoofSocket  |  Hierarchy Chart Hierarchy Chart


Get Surveyor!This web site was generated using Surveyor V4.50.811.1.  Click here for more information. Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003.