Ticket #1459: ControlSocket.cpp.patch
File ControlSocket.cpp.patch, 2.2 KB (added by , 20 years ago) |
---|
-
C:/Documents
2525 2554 // Get local port 2526 2555 SOCKADDR_IN addr; 2527 2556 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 2528 2572 if (GetSockName((SOCKADDR *)&addr, &len)) 2529 2573 { 2530 2574 int nPort = ntohs(addr.sin_port); 2531 2575 // Try create control conn. port - 1 2532 2576 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)) 2534 2579 bCreated = TRUE; 2535 2580 // Try create control conn. port + 1 if necessary 2536 2581 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)) 2538 2584 bCreated = TRUE; 2585 } 2586 } 2539 2587 } 2540 2588 if (!bCreated) 2589 { 2541 2590 // 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)) 2543 2592 { 2544 2593 // Give up 2545 2594 Send("421 Can't create socket"); 2546 2595 ResetTransferstatus(); 2547 2596 return FALSE; 2548 } 2597 } 2598 } 2599 2549 2600 if (m_pGssLayer && m_pGssLayer->AuthSuccessful()) 2550 2601 m_transferstatus.socket->UseGSS(m_pGssLayer); 2551 2602