Ticket #1459: ControlSocket.cpp.patch

File ControlSocket.cpp.patch, 2.2 KB (added by dartonw, 19 years ago)

ControlSocket.cpp Patch

  • C:/Documents

     
    25252554    // Get local port
    25262555    SOCKADDR_IN addr;
    25272556    int len = sizeof(addr);
     2557
     2558    // Fix: Formerly, the data connection would always be opened using the server's default (primary) IP.
     2559    // This would cause Windows Firewall to freak out if control connection was opened on a secondary IP.
     2560    // When using Active FTP behind Windows Firewall, no connection could be made. This fix ensures the data
     2561    // socket is on the same IP as the control socket.
     2562    // 12/13/2004 - DKW
     2563    CStdString ControlIP;
     2564    SOCKADDR_IN sockAddr;
     2565
     2566    memset(&sockAddr, 0, sizeof(sockAddr));
     2567    int nSockAddrLen = sizeof(sockAddr);
     2568    BOOL bResult = this->GetSockName((SOCKADDR*)&sockAddr, &nSockAddrLen);
     2569    if (bResult)
     2570        ControlIP = inet_ntoa(sockAddr.sin_addr);
     2571
    25282572    if (GetSockName((SOCKADDR *)&addr, &len))
    25292573    {
    25302574        int nPort = ntohs(addr.sin_port);
    25312575        // Try create control conn. port - 1
    25322576        if (nPort > 1)
    2533             if (pTransferSocket->Create(nPort - 1, SOCK_STREAM, FD_CONNECT))
     2577        {
     2578            if (pTransferSocket->Create(nPort - 1, SOCK_STREAM, FD_CONNECT, ControlIP))
    25342579                bCreated = TRUE;
    25352580            // Try create control conn. port + 1 if necessary
    25362581            if (!bCreated && nPort < 65535)
    2537                 if (pTransferSocket->Create(nPort + 1, SOCK_STREAM, FD_CONNECT))
     2582            {
     2583                if (pTransferSocket->Create(nPort + 1, SOCK_STREAM, FD_CONNECT, ControlIP))
    25382584                    bCreated = TRUE;
     2585            }
     2586        }
    25392587    }
    25402588    if (!bCreated)
     2589    {
    25412590        // Let the OS find a valid port
    2542         if (!pTransferSocket->Create(0, SOCK_STREAM, FD_CONNECT))
     2591        if (!pTransferSocket->Create(0, SOCK_STREAM, FD_CONNECT, ControlIP))
    25432592        {
    25442593            // Give up
    25452594            Send("421 Can't create socket");
    25462595            ResetTransferstatus();
    25472596            return FALSE;
    2548         }           
     2597        }
     2598    }
     2599
    25492600    if (m_pGssLayer && m_pGssLayer->AuthSuccessful())
    25502601        m_transferstatus.socket->UseGSS(m_pGssLayer);
    25512602