Class CTCPSocket::
Connect()
Base ClassesData ItemsConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: AcceptedNext page: ConstructTCPHeader    Show member index
Public Function Declared in:
TCPSocket.h

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

virtual BOOL Connect(
    int iSourcePort,
    LPCSTR lpDestinationAddress,
    int iDestinationPort);

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

Connect to a remote system

'Function Body' icon -- Shortcut to top of page. 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(iSourcePort,iDestinationPort,iHeaderLength);

        //Set the flags
        SetHeaderFlag(lpHead,TCPFlag_ACK);

        //Result
        BOOL bResult;

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

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

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

            //Checksum it
            lpHead->Checksum=CalculatePseudoChecksum(buf,iHeaderLength,lpDestinationAddress,iHeaderLength);

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

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

            //Dispose
            delete buf;
        }
        else
        {
            lpHead->Checksum=CalculatePseudoChecksum((char*)lpHead,TCPHeaderLength,lpDestinationAddress,TCPHeaderLength);

            //Send the data
            bResult=CSpoofSocket::Send(lpDestinationAddress,(char*)lpHead,TCPHeaderLength);
        }

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

        //Dispose the header
        delete lpHead;

        return bResult;
    }
    else
    {
        //Set async notification
        int iResult;

        //Create the address
        sockaddr_in soSrc;

        //Set to 0
        memset(&soSrc,0,sizeof(soSrc));
        soSrc.sin_family=AF_INET;
        soSrc.sin_addr.s_addr=inet_addr(lpDestinationAddress);
        soSrc.sin_port=htons(iDestinationPort);

        iResult=connect(GetHandle(),(sockaddr*)&soSrc,sizeof(soSrc));

        //Check the result
        if (iResult==SOCKET_ERROR)
        {
            //Check is it blocking error so we can ignore
            if (WSAGetLastError()!=WSAEWOULDBLOCK )
                SetLastError("Connect");
            else
                iResult=!SOCKET_ERROR;
        }
        else
            SetLastError("Connect");

        if (iResult!=SOCKET_ERROR)
            //Save where we are connected
            m_ConnectedTo=soSrc;

        return iResult!=SOCKET_ERROR;
    }
}
ERROR_HANDLER_RETURN("Connect",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: 24 Apr 2001.