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

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

BOOL Send(
    int iSourcePort,
    LPCSTR lpDestinationAddress,
    int iDestinationPort,
    const char* buf,
    int BufLength);

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

Send data

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

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

    //We can construct the UDP here
    LPUDPHeader lpUDP;
    lpUDP=new UDPHeader;

    //Set the ports
    lpUDP->SourcePort=htons(iSourcePort);
    lpUDP->DestinationPort=htons(iDestinationPort);

    //Set the length
    lpUDP->Length=htons(UDPHeaderLength);

    //Check sum
    lpUDP->Checksum=0;

    BOOL bResult;

    if (BufLength)
    {
        //Create the buffer
        int iTotalLength;
        iTotalLength=UDPHeaderLength+BufLength;

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

        //Set the length
        lpUDP->Length=htons(iTotalLength);

        memcpy(tmpBuf,lpUDP,UDPHeaderLength);
        memcpy(tmpBuf+UDPHeaderLength,buf,BufLength);

        //Update it
        lpUDP->Checksum=CalculatePseudoChecksum(tmpBuf,iTotalLength,lpDestinationAddress,iTotalLength);

        //Recopy it
        memcpy(tmpBuf,lpUDP,UDPHeaderLength);

        //Set the new checksum (if applicateable)
        FinalUDPHeader(lpUDP);

        //Send it
        bResult=CSpoofSocket::Send(lpDestinationAddress,tmpBuf,iTotalLength,iDestinationPort);

        //Delete
        delete tmpBuf;
    }
    else
    {
        //Update it
        lpUDP->Checksum=CalculatePseudoChecksum((char*)lpUDP,UDPHeaderLength,lpDestinationAddress,UDPHeaderLength);

        //Set the new checksum (if applicateable)
        FinalUDPHeader(lpUDP);

        //Send it
        bResult=CSpoofSocket::Send(lpDestinationAddress,(char*)lpUDP,UDPHeaderLength,iDestinationPort);
    }

    //Clean up
    delete lpUDP;

    return bResult;
}
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 © 2001 Barak Weichselbaum. See the About page for additional notices. This page last updated: 27 Jun 2001.