Class CSpoofSocket::
CalculatePseudoChecksum()
Base ClassesData ItemsConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: CalculateChecksumNext page: CanRead    Show member index
Public Function Declared in:
SpoofSocket.h

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

unsigned short CalculatePseudoChecksum(
    const char* pBuffer,
    int iBufferLength,
    IP aDestinationAddress,
    int iPacketLength) const;

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

Calculate the checksum for TCP and UDP

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

try
{
    //Calculate the checksum
    LPPseudoHeader lpPseudo;
    lpPseudo=new PseudoHeader;

    //Protect it
    std::auto_ptr<PseudoHeader> pProtection(lpPseudo);

    //Set the values
    lpPseudo->ulDestinationAddress=aDestinationAddress;
    lpPseudo->ulSourceAddress=m_ulSourceAddress;
    lpPseudo->ucZeros=0;
    lpPseudo->ucPTCL=m_ucProtocol;
    lpPseudo->usLength=htons(iPacketLength);

    //Calculate checksum of all
    int iTotalLength;
    iTotalLength=PseudoHeaderLength+iBufferLength;

    //Allocate the buffer
    char* pNewBuffer;
    pNewBuffer=new char[iTotalLength];

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

    //Copy pseudo
    memcpy(pNewBuffer,lpPseudo,PseudoHeaderLength);

    //Copy header
    memcpy(pNewBuffer+PseudoHeaderLength,
           pBuffer,
           iBufferLength);

    //Calculate the checksum
    unsigned short usChecksum;
    usChecksum=CalculateChecksum((unsigned short*)pNewBuffer,iTotalLength);

    //Return checksum
    return usChecksum;
}
ERROR_HANDLER_RETURN("CalculatePseudoChecksum",0)

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

Class Overview Class Overview  |  Public base class CSpoofBase  |  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.