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())
        return SendRaw(iSourcePort,lpDestinationAddress,iDestinationPort,NULL,0,TCPFlag_SYN);
    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
#ifdef WIN32
            if (WSAGetLastError()!=WSAEWOULDBLOCK)
#else
            if (errno()!=EWOULDBLOCK)
#endif
                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: 27 Jun 2001.