| CSpoofSocket:: CalculatePseudoChecksum() |

Public Function | Declared in: SpoofSocket.h

## Declaration

    unsigned short CalculatePseudoChecksum(
        const char *buf,
        int BufLength,
        LPCSTR lpDestinationAddress,
        int iPacketLength) const;

## Description

Calculate the checksum for TCP and UDP

## Function Body

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

        lpPseudo->DestinationAddress=inet_addr(lpDestinationAddress);
        lpPseudo->SourceAddress=inet_addr(m_SourceAddress);
        lpPseudo->Zeros=0;
        lpPseudo->PTCL=m_Protocol;
        lpPseudo->Length=htons(iPacketLength);

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

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

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

        //Copy header
        memcpy(tmpBuf+PseudoHeaderLength,buf,BufLength);

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

        //Delete all
        delete tmpBuf;
        delete lpPseudo;

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

## See Also

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