mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- some initial changes to try to get ftp working over the Internet with firewalls etc
This commit is contained in:
parent
2ca50ee9f9
commit
3f0ee7a6cb
@ -503,7 +503,7 @@ void MenuStateJoinGame::keyDown(char key){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateJoinGame::keyPress(char c){
|
void MenuStateJoinGame::keyPress(char c) {
|
||||||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
|
|
||||||
if(clientInterface->isConnected() == false) {
|
if(clientInterface->isConnected() == false) {
|
||||||
@ -511,34 +511,28 @@ void MenuStateJoinGame::keyPress(char c){
|
|||||||
|
|
||||||
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
||||||
|
|
||||||
if(c>='0' && c<='9'){
|
if(c>='0' && c<='9') {
|
||||||
|
|
||||||
if(labelServerIp.getText().size()<maxTextSize){
|
if(labelServerIp.getText().size()<maxTextSize) {
|
||||||
string text= labelServerIp.getText();
|
string text= labelServerIp.getText();
|
||||||
|
|
||||||
text.insert(text.end()-1, c);
|
text.insert(text.end()-1, c);
|
||||||
|
|
||||||
labelServerIp.setText(text);
|
labelServerIp.setText(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (c=='.'){
|
else if (c=='.') {
|
||||||
if(labelServerIp.getText().size()<maxTextSize){
|
if(labelServerIp.getText().size() < maxTextSize) {
|
||||||
string text= labelServerIp.getText();
|
string text= labelServerIp.getText();
|
||||||
|
|
||||||
text.insert(text.end()-1, '.');
|
text.insert(text.end()-1, '.');
|
||||||
|
|
||||||
labelServerIp.setText(text);
|
labelServerIp.setText(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
chatManager.keyPress(c);
|
chatManager.keyPress(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateJoinGame::connectToServer()
|
void MenuStateJoinGame::connectToServer() {
|
||||||
{
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
||||||
|
|
||||||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
|
@ -226,7 +226,7 @@ void ClientInterface::updateLobby() {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//send intro message
|
//send intro message
|
||||||
NetworkMessageIntro sendNetworkMessageIntro(sessionKey,getNetworkVersionString(), getHumanPlayerName(), -1, nmgstOk);
|
NetworkMessageIntro sendNetworkMessageIntro(sessionKey,getNetworkVersionString(), getHumanPlayerName(), -1, nmgstOk, this->getSocket()->getConnectedIPAddress());
|
||||||
sendMessage(&sendNetworkMessageIntro);
|
sendMessage(&sendNetworkMessageIntro);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
@ -158,6 +158,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
this->connectedRemoteIPAddress = 0;
|
||||||
this->sessionKey = 0;
|
this->sessionKey = 0;
|
||||||
this->serverInterface = serverInterface;
|
this->serverInterface = serverInterface;
|
||||||
this->playerIndex = playerIndex;
|
this->playerIndex = playerIndex;
|
||||||
@ -257,7 +258,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] !!!!!!!!WARNING - no open slots, disconnecting client\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] !!!!!!!!WARNING - no open slots, disconnecting client\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(socket != NULL) {
|
if(socket != NULL) {
|
||||||
NetworkMessageIntro networkMessageIntro(sessionKey,getNetworkVersionString(), getHostName(), playerIndex, nmgstNoSlots);
|
NetworkMessageIntro networkMessageIntro(sessionKey,getNetworkVersionString(), getHostName(), playerIndex, nmgstNoSlots, 0);
|
||||||
sendMessage(&networkMessageIntro);
|
sendMessage(&networkMessageIntro);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +268,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] client will be assigned to the next open slot\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] client will be assigned to the next open slot\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(socket != NULL) {
|
if(socket != NULL) {
|
||||||
NetworkMessageIntro networkMessageIntro(sessionKey,getNetworkVersionString(), getHostName(), playerIndex, nmgstOk);
|
NetworkMessageIntro networkMessageIntro(sessionKey,getNetworkVersionString(), getHostName(), playerIndex, nmgstOk, 0);
|
||||||
sendMessage(&networkMessageIntro);
|
sendMessage(&networkMessageIntro);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,6 +363,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
int msgSessionId = networkMessageIntro.getSessionId();
|
int msgSessionId = networkMessageIntro.getSessionId();
|
||||||
name= networkMessageIntro.getName();
|
name= networkMessageIntro.getName();
|
||||||
versionString = networkMessageIntro.getVersionString();
|
versionString = networkMessageIntro.getVersionString();
|
||||||
|
this->connectedRemoteIPAddress = networkMessageIntro.getExternalIp();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got name [%s] versionString [%s], msgSessionId = %d\n",__FILE__,__FUNCTION__,name.c_str(),versionString.c_str(),msgSessionId);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got name [%s] versionString [%s], msgSessionId = %d\n",__FILE__,__FUNCTION__,name.c_str(),versionString.c_str(),msgSessionId);
|
||||||
|
|
||||||
@ -423,6 +425,8 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
gotIntro = true;
|
gotIntro = true;
|
||||||
|
|
||||||
|
this->serverInterface->addClientToServerIPAddress(this->getSocket()->getConnectedIPAddress(this->getSocket()->getIp()),this->connectedRemoteIPAddress);
|
||||||
|
|
||||||
if(getAllowGameDataSynchCheck() == true && serverInterface->getGameSettings() != NULL) {
|
if(getAllowGameDataSynchCheck() == true && serverInterface->getGameSettings() != NULL) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -114,6 +114,7 @@ private:
|
|||||||
bool gotLagCountWarning;
|
bool gotLagCountWarning;
|
||||||
string versionString;
|
string versionString;
|
||||||
int sessionKey;
|
int sessionKey;
|
||||||
|
uint32 connectedRemoteIPAddress;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConnectionSlot(ServerInterface* serverInterface, int playerIndex);
|
ConnectionSlot(ServerInterface* serverInterface, int playerIndex);
|
||||||
@ -124,6 +125,8 @@ public:
|
|||||||
void setPlayerIndex(int value) { playerIndex = value; }
|
void setPlayerIndex(int value) { playerIndex = value; }
|
||||||
int getPlayerIndex() {return playerIndex;}
|
int getPlayerIndex() {return playerIndex;}
|
||||||
|
|
||||||
|
uint32 getConnectedRemoteIPAddress() const { return connectedRemoteIPAddress; }
|
||||||
|
|
||||||
void setReady() {ready= true;}
|
void setReady() {ready= true;}
|
||||||
const string &getName() const {return name;}
|
const string &getName() const {return name;}
|
||||||
void setName(string value) {name = value;}
|
void setName(string value) {name = value;}
|
||||||
|
@ -123,22 +123,25 @@ void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const
|
|||||||
// class NetworkMessageIntro
|
// class NetworkMessageIntro
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
NetworkMessageIntro::NetworkMessageIntro(){
|
NetworkMessageIntro::NetworkMessageIntro() {
|
||||||
data.messageType= -1;
|
data.messageType= -1;
|
||||||
data.sessionId= -1;
|
data.sessionId= -1;
|
||||||
data.playerIndex= -1;
|
data.playerIndex= -1;
|
||||||
data.gameState = nmgstInvalid;
|
data.gameState = nmgstInvalid;
|
||||||
|
data.externalIp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkMessageIntro::NetworkMessageIntro(int32 sessionId,const string &versionString,
|
NetworkMessageIntro::NetworkMessageIntro(int32 sessionId,const string &versionString,
|
||||||
const string &name, int playerIndex,
|
const string &name, int playerIndex,
|
||||||
NetworkGameStateType gameState) {
|
NetworkGameStateType gameState,
|
||||||
|
uint32 externalIp) {
|
||||||
data.messageType = nmtIntro;
|
data.messageType = nmtIntro;
|
||||||
data.sessionId = sessionId;
|
data.sessionId = sessionId;
|
||||||
data.versionString = versionString;
|
data.versionString = versionString;
|
||||||
data.name = name;
|
data.name = name;
|
||||||
data.playerIndex = static_cast<int16>(playerIndex);
|
data.playerIndex = static_cast<int16>(playerIndex);
|
||||||
data.gameState = static_cast<int8>(gameState);
|
data.gameState = static_cast<int8>(gameState);
|
||||||
|
data.externalIp = externalIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkMessageIntro::receive(Socket* socket){
|
bool NetworkMessageIntro::receive(Socket* socket){
|
||||||
|
@ -84,13 +84,14 @@ private:
|
|||||||
static const int maxNameSize= 32;
|
static const int maxNameSize= 32;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Data{
|
struct Data {
|
||||||
int8 messageType;
|
int8 messageType;
|
||||||
int32 sessionId;
|
int32 sessionId;
|
||||||
NetworkString<maxVersionStringSize> versionString;
|
NetworkString<maxVersionStringSize> versionString;
|
||||||
NetworkString<maxNameSize> name;
|
NetworkString<maxNameSize> name;
|
||||||
int16 playerIndex;
|
int16 playerIndex;
|
||||||
int8 gameState;
|
int8 gameState;
|
||||||
|
uint32 externalIp;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -98,13 +99,14 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
NetworkMessageIntro();
|
NetworkMessageIntro();
|
||||||
NetworkMessageIntro(int32 sessionId, const string &versionString, const string &name, int playerIndex, NetworkGameStateType gameState);
|
NetworkMessageIntro(int32 sessionId, const string &versionString, const string &name, int playerIndex, NetworkGameStateType gameState, uint32 externalIp);
|
||||||
|
|
||||||
int32 getSessionId() const { return data.sessionId;}
|
int32 getSessionId() const { return data.sessionId;}
|
||||||
string getVersionString() const { return data.versionString.getString(); }
|
string getVersionString() const { return data.versionString.getString(); }
|
||||||
string getName() const { return data.name.getString(); }
|
string getName() const { return data.name.getString(); }
|
||||||
int getPlayerIndex() const { return data.playerIndex; }
|
int getPlayerIndex() const { return data.playerIndex; }
|
||||||
NetworkGameStateType getGameState() const { return static_cast<NetworkGameStateType>(data.gameState); }
|
NetworkGameStateType getGameState() const { return static_cast<NetworkGameStateType>(data.gameState); }
|
||||||
|
uint32 getExternalIp() const { return data.externalIp;}
|
||||||
|
|
||||||
virtual bool receive(Socket* socket);
|
virtual bool receive(Socket* socket);
|
||||||
virtual void send(Socket* socket) const;
|
virtual void send(Socket* socket) const;
|
||||||
|
@ -143,6 +143,10 @@ ServerInterface::~ServerInterface() {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerInterface::addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp) {
|
||||||
|
FTPServerThread::addClientToServerIPAddress(clientIp,ServerIp);
|
||||||
|
}
|
||||||
|
|
||||||
void ServerInterface::addSlot(int playerIndex) {
|
void ServerInterface::addSlot(int playerIndex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -122,6 +122,7 @@ public:
|
|||||||
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
|
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
|
||||||
|
|
||||||
virtual void simpleTask();
|
virtual void simpleTask();
|
||||||
|
void addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -61,7 +61,9 @@ typedef struct
|
|||||||
int rxBufWriteIdx; ///< currect write index of receive buffer rxBuf
|
int rxBufWriteIdx; ///< currect write index of receive buffer rxBuf
|
||||||
char rxBuf[LEN_RXBUF]; ///< receive buffer for ftp commands
|
char rxBuf[LEN_RXBUF]; ///< receive buffer for ftp commands
|
||||||
char workingDir[MAX_PATH_LEN]; ///< current working directory (absolute path which is relative to the root-path of the user account)
|
char workingDir[MAX_PATH_LEN]; ///< current working directory (absolute path which is relative to the root-path of the user account)
|
||||||
ip_t remoteIp; ///< IP of connected ftp client
|
ip_t remoteIp; ///< IP of connected ftp client
|
||||||
|
//ip_t remoteFTPServerIp; ///< IP of the FTP Server from the clients perspective
|
||||||
|
port_t remoteFTPServerPassivePort; ///< Port of the FTP Server from the clients perspective related to Passive connection
|
||||||
port_t remotePort; ///< Port of connected ftp client for control connection
|
port_t remotePort; ///< Port of connected ftp client for control connection
|
||||||
port_t remoteDataPort; ///< Port of connected ftp client for data connection
|
port_t remoteDataPort; ///< Port of connected ftp client for data connection
|
||||||
int passive; ///< TRUE, if passive-mode is activated via PSV command
|
int passive; ///< TRUE, if passive-mode is activated via PSV command
|
||||||
@ -127,7 +129,7 @@ typedef struct
|
|||||||
|
|
||||||
extern int ftpOpenSession(socket_t ctrlSocket, ip_t remoteIp, port_t remotePort);
|
extern int ftpOpenSession(socket_t ctrlSocket, ip_t remoteIp, port_t remotePort);
|
||||||
extern int ftpCloseSession(int id);
|
extern int ftpCloseSession(int id);
|
||||||
extern ftpSession_S* ftpGetSession(int id);
|
extern ftpSession_S* ftpGetSession(int id);
|
||||||
extern int ftpAuthSession(int id);
|
extern int ftpAuthSession(int id);
|
||||||
extern const char* ftpGetRealPath(int id, const char* path, int normalize);
|
extern const char* ftpGetRealPath(int id, const char* path, int normalize);
|
||||||
extern int ftpChangeDir(int id, const char* path);
|
extern int ftpChangeDir(int id, const char* path);
|
||||||
@ -151,7 +153,7 @@ extern uint32_t ftpGetUnixTime(void);
|
|||||||
extern char *ftpStrcpy(char *dest, const char *src);
|
extern char *ftpStrcpy(char *dest, const char *src);
|
||||||
|
|
||||||
|
|
||||||
extern void ftpArchInit(void);
|
extern void ftpArchInit();
|
||||||
extern void ftpArchCleanup(void);
|
extern void ftpArchCleanup(void);
|
||||||
extern int ftpGetLocalTime(ftpTime_S *t);
|
extern int ftpGetLocalTime(ftpTime_S *t);
|
||||||
extern void* ftpOpenDir(const char* path);
|
extern void* ftpOpenDir(const char* path);
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#define FTP_ACC_DIR 8
|
#define FTP_ACC_DIR 8
|
||||||
#define FTP_ACC_FULL (FTP_ACC_RD | FTP_ACC_WR | FTP_ACC_LS | FTP_ACC_DIR)
|
#define FTP_ACC_FULL (FTP_ACC_RD | FTP_ACC_WR | FTP_ACC_LS | FTP_ACC_DIR)
|
||||||
|
|
||||||
|
#include "ftpTypes.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -40,7 +42,7 @@ int ftpCreateAccount(const char* name, const char* passw, const char* root, int
|
|||||||
int ftpStart(int portNumber);
|
int ftpStart(int portNumber);
|
||||||
int ftpShutdown(void);
|
int ftpShutdown(void);
|
||||||
void ftpExecute(void);
|
void ftpExecute(void);
|
||||||
int ftpState(void);
|
int ftpState(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* ftpTypes.h - global type definitions
|
* ftpTypes.h - global type definitions
|
||||||
*
|
*
|
||||||
* Definitions of fixed size integers an helper macros.
|
* Definitions of fixed size integers an helper macros.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -59,5 +59,10 @@ typedef uint16_t port_t;
|
|||||||
#ifndef TRUE
|
#ifndef TRUE
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ip_t (*ftpFindExternalFTPServerIp)(ip_t clientIp);
|
||||||
|
void (*ftpAddUPNPPortForward)(int internalPort, int externalPort);
|
||||||
|
void (*ftpRemoveUPNPPortForward)(int internalPort, int externalPort);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "base_thread.h"
|
#include "base_thread.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
@ -25,12 +26,14 @@ namespace Shared { namespace PlatformCommon {
|
|||||||
// =====================================================
|
// =====================================================
|
||||||
// class FTPServerThread
|
// class FTPServerThread
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
uint32 FindExternalFTPServerIp(uint32 clientIp);
|
||||||
|
|
||||||
class FTPServerThread : public BaseThread
|
class FTPServerThread : public BaseThread
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::pair<string,string> mapsPath;
|
std::pair<string,string> mapsPath;
|
||||||
int portNumber;
|
int portNumber;
|
||||||
|
//uint32 externalIp;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -38,6 +41,9 @@ public:
|
|||||||
virtual void execute();
|
virtual void execute();
|
||||||
virtual void signalQuit();
|
virtual void signalQuit();
|
||||||
virtual bool shutdownAndWait();
|
virtual bool shutdownAndWait();
|
||||||
|
|
||||||
|
static void addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "base_thread.h"
|
#include "base_thread.h"
|
||||||
#include "simple_threads.h"
|
#include "simple_threads.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
@ -49,6 +50,10 @@ using namespace Shared::PlatformCommon;
|
|||||||
|
|
||||||
namespace Shared{ namespace Platform {
|
namespace Shared{ namespace Platform {
|
||||||
|
|
||||||
|
|
||||||
|
void AddUPNPPortForward(int internalPort, int externalPort);
|
||||||
|
void RemoveUPNPPortForward(int internalPort, int externalPort);
|
||||||
|
|
||||||
//
|
//
|
||||||
// This interface describes the methods a callback object must implement
|
// This interface describes the methods a callback object must implement
|
||||||
// when signaled with detected servers
|
// when signaled with detected servers
|
||||||
@ -99,6 +104,7 @@ protected:
|
|||||||
time_t lastDebugEvent;
|
time_t lastDebugEvent;
|
||||||
static int broadcast_portno;
|
static int broadcast_portno;
|
||||||
std::string ipAddress;
|
std::string ipAddress;
|
||||||
|
std::string connectedIpAddress;
|
||||||
|
|
||||||
SimpleTaskThread *pingThread;
|
SimpleTaskThread *pingThread;
|
||||||
std::map<string,double> pingCache;
|
std::map<string,double> pingCache;
|
||||||
@ -149,6 +155,8 @@ public:
|
|||||||
virtual std::string getIpAddress();
|
virtual std::string getIpAddress();
|
||||||
virtual void setIpAddress(std::string value) { ipAddress = value; }
|
virtual void setIpAddress(std::string value) { ipAddress = value; }
|
||||||
|
|
||||||
|
uint32 getConnectedIPAddress(string IP="");
|
||||||
|
|
||||||
static bool isUPNP;
|
static bool isUPNP;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -219,6 +227,10 @@ public:
|
|||||||
|
|
||||||
void NETdiscoverUPnPDevices();
|
void NETdiscoverUPnPDevices();
|
||||||
|
|
||||||
|
static bool enabledUPNP;
|
||||||
|
static bool upnp_add_redirect(int ports[2]);
|
||||||
|
static void upnp_rem_redirect(int ext_port);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool portBound;
|
bool portBound;
|
||||||
@ -227,15 +239,11 @@ protected:
|
|||||||
static int externalPort;
|
static int externalPort;
|
||||||
static int ftpServerPort;
|
static int ftpServerPort;
|
||||||
|
|
||||||
static bool enabledUPNP;
|
|
||||||
|
|
||||||
BroadCastSocketThread *broadCastThread;
|
BroadCastSocketThread *broadCastThread;
|
||||||
void startBroadCastThread();
|
void startBroadCastThread();
|
||||||
bool isBroadCastThreadRunning();
|
bool isBroadCastThreadRunning();
|
||||||
|
|
||||||
static int upnp_init(void *param);
|
static int upnp_init(void *param);
|
||||||
static bool upnp_add_redirect(int ports[4]);
|
|
||||||
static void upnp_rem_redirect(int ext_port);
|
|
||||||
|
|
||||||
void NETaddRedirects(int ports[4]);
|
void NETaddRedirects(int ports[4]);
|
||||||
void NETremRedirects(int ext_port);
|
void NETremRedirects(int ext_port);
|
||||||
|
@ -679,15 +679,38 @@ LOCAL int ftpCmdPasv(int sessionId, const char* args, int len)
|
|||||||
ftpSendMsg(MSG_NORMAL, sessionId, 425, ftpMsg012);
|
ftpSendMsg(MSG_NORMAL, sessionId, 425, ftpMsg012);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ftpGetSession(sessionId)->passiveDataSocket = s;
|
ftpGetSession(sessionId)->passiveDataSocket = s;
|
||||||
sprintf(str, "%s (%d,%d,%d,%d,%d,%d)",
|
|
||||||
ftpMsg029,
|
if(ftpFindExternalFTPServerIp(ftpGetSession(sessionId)->remoteIp) > 0)
|
||||||
(ip >> 24) & 0xFF,
|
{
|
||||||
(ip >> 16) & 0xFF,
|
ftpGetSession(sessionId)->remoteFTPServerPassivePort = port;
|
||||||
(ip >> 8) & 0xFF,
|
if(ftpAddUPNPPortForward) {
|
||||||
ip & 0xFF,
|
ftpAddUPNPPortForward(port, port);
|
||||||
(port >> 8) & 0xFF,
|
}
|
||||||
port & 0xFF);
|
|
||||||
|
ip_t remoteFTPServerIp = ftpFindExternalFTPServerIp(ftpGetSession(sessionId)->remoteIp);
|
||||||
|
|
||||||
|
sprintf(str, "%s (%d,%d,%d,%d,%d,%d)",
|
||||||
|
ftpMsg029,
|
||||||
|
(remoteFTPServerIp >> 24) & 0xFF,
|
||||||
|
(remoteFTPServerIp >> 16) & 0xFF,
|
||||||
|
(remoteFTPServerIp >> 8) & 0xFF,
|
||||||
|
remoteFTPServerIp & 0xFF,
|
||||||
|
(port >> 8) & 0xFF,
|
||||||
|
port & 0xFF);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprintf(str, "%s (%d,%d,%d,%d,%d,%d)",
|
||||||
|
ftpMsg029,
|
||||||
|
(ip >> 24) & 0xFF,
|
||||||
|
(ip >> 16) & 0xFF,
|
||||||
|
(ip >> 8) & 0xFF,
|
||||||
|
ip & 0xFF,
|
||||||
|
(port >> 8) & 0xFF,
|
||||||
|
port & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
ftpSendMsg(MSG_NORMAL, sessionId, 227, str);
|
ftpSendMsg(MSG_NORMAL, sessionId, 227, str);
|
||||||
ftpGetSession(sessionId)->passive = TRUE;
|
ftpGetSession(sessionId)->passive = TRUE;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include "ftpConfig.h"
|
#include "ftpConfig.h"
|
||||||
#include "ftp.h"
|
#include "ftp.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief array that holds the data of all ftp sessions
|
* @brief array that holds the data of all ftp sessions
|
||||||
*
|
*
|
||||||
@ -119,7 +118,14 @@ int ftpAuthSession(int id)
|
|||||||
* @return 0
|
* @return 0
|
||||||
*/
|
*/
|
||||||
int ftpCloseSession(int id)
|
int ftpCloseSession(int id)
|
||||||
{
|
{
|
||||||
|
if(ftpFindExternalFTPServerIp != NULL && ftpFindExternalFTPServerIp(sessions[id].remoteIp) > 0)
|
||||||
|
{
|
||||||
|
if(ftpRemoveUPNPPortForward)
|
||||||
|
{
|
||||||
|
ftpRemoveUPNPPortForward(sessions[id].remoteFTPServerPassivePort, sessions[id].remoteFTPServerPassivePort);
|
||||||
|
}
|
||||||
|
}
|
||||||
ftpCloseSocket(sessions[id].ctrlSocket);
|
ftpCloseSocket(sessions[id].ctrlSocket);
|
||||||
ftpCloseTransmission(id);
|
ftpCloseTransmission(id);
|
||||||
|
|
||||||
|
@ -35,18 +35,20 @@
|
|||||||
|
|
||||||
#include "ftpTypes.h"
|
#include "ftpTypes.h"
|
||||||
#include "ftpConfig.h"
|
#include "ftpConfig.h"
|
||||||
#include "ftp.h"
|
#include "ftp.h"
|
||||||
|
|
||||||
ip_t ownIp;
|
ip_t ownIp;
|
||||||
|
//ip_t ownExternalIp;
|
||||||
|
|
||||||
LOCAL fd_set watchedSockets;
|
LOCAL fd_set watchedSockets;
|
||||||
LOCAL fd_set signaledSockets;
|
LOCAL fd_set signaledSockets;
|
||||||
LOCAL int maxSockNr;
|
LOCAL int maxSockNr;
|
||||||
|
|
||||||
|
|
||||||
void ftpArchInit(void)
|
void ftpArchInit()
|
||||||
{
|
{
|
||||||
ownIp = 0;
|
ownIp = 0;
|
||||||
|
//ownExternalIp = externalIp;
|
||||||
maxSockNr = 0;
|
maxSockNr = 0;
|
||||||
FD_ZERO(&watchedSockets);
|
FD_ZERO(&watchedSockets);
|
||||||
FD_ZERO(&signaledSockets);
|
FD_ZERO(&signaledSockets);
|
||||||
@ -260,7 +262,10 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*port = ntohs(myAddr.sin_port);
|
*port = ntohs(myAddr.sin_port);
|
||||||
*ip = ownIp;
|
*ip = ownIp;
|
||||||
|
//if(ownExternalIp > 0) {
|
||||||
|
// *ip = ownExternalIp;
|
||||||
|
//}
|
||||||
|
|
||||||
if(listen(dataSocket, 1))
|
if(listen(dataSocket, 1))
|
||||||
{
|
{
|
||||||
@ -339,7 +344,7 @@ socket_t ftpAcceptServerConnection(socket_t server, ip_t *remoteIP, port_t *remo
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ownIp = ntohl(sockinfo.sin_addr.s_addr); // eigene IP-Adresse abspeichern (wird dir PASV benätigt)
|
ownIp = ntohl(sockinfo.sin_addr.s_addr); // eigene IP-Adresse abspeichern (wird dir PASV benätigt)
|
||||||
}
|
}
|
||||||
#if DBG_LOG
|
#if DBG_LOG
|
||||||
printf("Verbindung mit %s auf Port %d akzeptiert.\n", inet_ntoa(sockinfo.sin_addr), *remotePort);
|
printf("Verbindung mit %s auf Port %d akzeptiert.\n", inet_ntoa(sockinfo.sin_addr), *remotePort);
|
||||||
|
@ -32,16 +32,18 @@
|
|||||||
#pragma comment(lib, "ws2_32")
|
#pragma comment(lib, "ws2_32")
|
||||||
#pragma comment(lib, "MSWSOCK")
|
#pragma comment(lib, "MSWSOCK")
|
||||||
|
|
||||||
ip_t ownIp;
|
ip_t ownIp;
|
||||||
|
//ip_t ownExternalIp;
|
||||||
|
|
||||||
LOCAL fd_set watchedSockets;
|
LOCAL fd_set watchedSockets;
|
||||||
LOCAL fd_set signaledSockets;
|
LOCAL fd_set signaledSockets;
|
||||||
LOCAL int maxSockNr;
|
LOCAL int maxSockNr;
|
||||||
|
|
||||||
void ftpArchInit(void)
|
void ftpArchInit()
|
||||||
{
|
{
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
ownIp = 0;
|
ownIp = 0;
|
||||||
|
//ownExternalIp = externalIp;
|
||||||
maxSockNr = 0;
|
maxSockNr = 0;
|
||||||
FD_ZERO(&watchedSockets);
|
FD_ZERO(&watchedSockets);
|
||||||
WSAStartup(MAKEWORD(2, 0),&wsaData);
|
WSAStartup(MAKEWORD(2, 0),&wsaData);
|
||||||
@ -291,6 +293,9 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port)
|
|||||||
|
|
||||||
*port = ntohs(myAddr.sin_port);
|
*port = ntohs(myAddr.sin_port);
|
||||||
*ip = ownIp;
|
*ip = ownIp;
|
||||||
|
//if(ownExternalIp > 0) {
|
||||||
|
// *ip = ownExternalIp;
|
||||||
|
//}
|
||||||
|
|
||||||
if(listen(dataSocket, 1))
|
if(listen(dataSocket, 1))
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "platform_common.h"
|
#include "platform_common.h"
|
||||||
#include "ftpIfc.h"
|
#include "ftpIfc.h"
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -25,9 +26,22 @@ using namespace Shared::PlatformCommon;
|
|||||||
|
|
||||||
namespace Shared { namespace PlatformCommon {
|
namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
|
static std::map<uint32,uint32> clientToFTPServerList;
|
||||||
|
|
||||||
|
uint32 FindExternalFTPServerIp(uint32 clientIp) {
|
||||||
|
return clientToFTPServerList[clientIp];
|
||||||
|
}
|
||||||
|
|
||||||
FTPServerThread::FTPServerThread(std::pair<string,string> mapsPath,int portNumber) : BaseThread() {
|
FTPServerThread::FTPServerThread(std::pair<string,string> mapsPath,int portNumber) : BaseThread() {
|
||||||
this->mapsPath = mapsPath;
|
this->mapsPath = mapsPath;
|
||||||
this->portNumber = portNumber;
|
this->portNumber = portNumber;
|
||||||
|
//this->externalIp = externalIp;
|
||||||
|
|
||||||
|
//void (*ftpAddUPNPPortForward)(int internalPort, int externalPort) = NULL;
|
||||||
|
//void (*ftpRemoveUPNPPortForward)(int internalPort, int externalPort) = NULL;
|
||||||
|
ftpAddUPNPPortForward = &AddUPNPPortForward;
|
||||||
|
ftpRemoveUPNPPortForward = &RemoveUPNPPortForward;
|
||||||
|
ftpFindExternalFTPServerIp = &FindExternalFTPServerIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FTPServerThread::signalQuit() {
|
void FTPServerThread::signalQuit() {
|
||||||
@ -39,7 +53,14 @@ bool FTPServerThread::shutdownAndWait() {
|
|||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server: shutdownAndWait\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server: shutdownAndWait\n");
|
||||||
|
|
||||||
signalQuit();
|
signalQuit();
|
||||||
return BaseThread::shutdownAndWait();
|
bool ret = BaseThread::shutdownAndWait();
|
||||||
|
clientToFTPServerList.clear();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FTPServerThread::addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp) {
|
||||||
|
//ftpSetSessionRemoteServerIp(clientIp, ServerIp);
|
||||||
|
clientToFTPServerList[clientIp] = ServerIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FTPServerThread::execute() {
|
void FTPServerThread::execute() {
|
||||||
|
@ -620,6 +620,20 @@ string getNetworkInterfaceBroadcastAddress(string ipAddress)
|
|||||||
return broadCastAddress;
|
return broadCastAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 Socket::getConnectedIPAddress(string IP) {
|
||||||
|
sockaddr_in addr;
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
|
||||||
|
addr.sin_family= AF_INET;
|
||||||
|
if(IP == "") {
|
||||||
|
IP = connectedIpAddress;
|
||||||
|
}
|
||||||
|
addr.sin_addr.s_addr= inet_addr(IP.c_str());
|
||||||
|
//addr.sin_port= htons(port);
|
||||||
|
|
||||||
|
return SockAddrToUint32((struct sockaddr *)&addr);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> Socket::getLocalIPAddressList() {
|
std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
std::vector<std::string> ipList;
|
std::vector<std::string> ipList;
|
||||||
|
|
||||||
@ -734,14 +748,16 @@ bool Socket::isSocketValid(const PLATFORM_SOCKET *validateSocket) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Socket(PLATFORM_SOCKET sock){
|
Socket::Socket(PLATFORM_SOCKET sock) {
|
||||||
this->pingThread = NULL;
|
this->pingThread = NULL;
|
||||||
this->sock= sock;
|
this->sock= sock;
|
||||||
|
this->connectedIpAddress = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Socket()
|
Socket::Socket() {
|
||||||
{
|
|
||||||
this->pingThread = NULL;
|
this->pingThread = NULL;
|
||||||
|
this->connectedIpAddress = "";
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if(isSocketValid() == false) {
|
if(isSocketValid() == false) {
|
||||||
throwException("Error creating socket");
|
throwException("Error creating socket");
|
||||||
@ -1411,6 +1427,7 @@ void ClientSocket::connect(const Ip &ip, int port)
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connecting to host [%s] on port = %d\n", ip.getString().c_str(),port);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connecting to host [%s] on port = %d\n", ip.getString().c_str(),port);
|
||||||
|
|
||||||
|
connectedIpAddress = "";
|
||||||
int err= ::connect(sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr));
|
int err= ::connect(sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr));
|
||||||
if(err < 0) {
|
if(err < 0) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 Error connecting socket for IP: %s for Port: %d err = %d error = %s\n",__FILE__,__FUNCTION__,ip.getString().c_str(),port,err,getLastSocketErrorFormattedText().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 Error connecting socket for IP: %s for Port: %d err = %d error = %s\n",__FILE__,__FUNCTION__,ip.getString().c_str(),port,err,getLastSocketErrorFormattedText().c_str());
|
||||||
@ -1436,14 +1453,12 @@ void ClientSocket::connect(const Ip &ip, int port)
|
|||||||
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED)
|
if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED) {
|
||||||
{
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Error connecting %s\n",__FILE__,__FUNCTION__,getLastSocketErrorFormattedText().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Error connecting %s\n",__FILE__,__FUNCTION__,getLastSocketErrorFormattedText().c_str());
|
||||||
//throwException(szBuf);
|
//throwException(szBuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (err > 0)
|
else if (err > 0) {
|
||||||
{
|
|
||||||
// Socket selected for write
|
// Socket selected for write
|
||||||
lon = sizeof(int);
|
lon = sizeof(int);
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
@ -1457,8 +1472,7 @@ void ClientSocket::connect(const Ip &ip, int port)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Check the value returned...
|
// Check the value returned...
|
||||||
if (valopt)
|
if(valopt) {
|
||||||
{
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Error in delayed connection() %d - [%s]\n",__FILE__,__FUNCTION__,valopt, strerror(valopt));
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Error in delayed connection() %d - [%s]\n",__FILE__,__FUNCTION__,valopt, strerror(valopt));
|
||||||
//throwException(szBuf);
|
//throwException(szBuf);
|
||||||
break;
|
break;
|
||||||
@ -1469,8 +1483,7 @@ void ClientSocket::connect(const Ip &ip, int port)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Timeout in select() - Cancelling!\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Timeout in select() - Cancelling!\n",__FILE__,__FUNCTION__);
|
||||||
//throwException(szBuf);
|
//throwException(szBuf);
|
||||||
|
|
||||||
@ -1480,20 +1493,19 @@ void ClientSocket::connect(const Ip &ip, int port)
|
|||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(err < 0)
|
if(err < 0) {
|
||||||
{
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Before END sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Before END sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str());
|
||||||
//throwException(szBuf);
|
//throwException(szBuf);
|
||||||
disconnectSocket();
|
disconnectSocket();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Valid recovery for connection sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Valid recovery for connection sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str());
|
||||||
|
connectedIpAddress = ip.getString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connected to host [%s] on port = %d sock = %d err = %d", ip.getString().c_str(),port,sock,err);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connected to host [%s] on port = %d sock = %d err = %d", ip.getString().c_str(),port,sock,err);
|
||||||
|
connectedIpAddress = ip.getString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1824,6 +1836,85 @@ Socket *ServerSocket::accept() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddUPNPPortForward(int internalPort, int externalPort) {
|
||||||
|
struct UPNPDev *devlist=NULL;
|
||||||
|
struct UPNPDev *dev=NULL;
|
||||||
|
char *descXML=NULL;
|
||||||
|
int descXMLsize = 0;
|
||||||
|
char buf[255]="";
|
||||||
|
//int *externalPort = (int *)asdf;
|
||||||
|
|
||||||
|
memset(&urls, 0, sizeof(struct UPNPUrls));
|
||||||
|
memset(&data, 0, sizeof(struct IGDdatas));
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Socket::isUPNP = %d\n", Socket::isUPNP);
|
||||||
|
|
||||||
|
if(Socket::isUPNP) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Searching for UPnP devices for automatic port forwarding...\n");
|
||||||
|
devlist = upnpDiscover(2000, NULL, NULL, 0);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"UPnP device search finished.\n");
|
||||||
|
|
||||||
|
if (devlist) {
|
||||||
|
dev = devlist;
|
||||||
|
while (dev) {
|
||||||
|
if (strstr(dev->st, "InternetGatewayDevice"))
|
||||||
|
break;
|
||||||
|
dev = dev->pNext;
|
||||||
|
}
|
||||||
|
if (!dev) {
|
||||||
|
dev = devlist; /* defaulting to first device */
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"UPnP device found: %s %s\n", dev->descURL, dev->st);
|
||||||
|
|
||||||
|
descXML = (char *)miniwget_getaddr(dev->descURL, &descXMLsize, lanaddr, sizeof(lanaddr));
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"LAN address: %s\n", lanaddr);
|
||||||
|
if (descXML) {
|
||||||
|
parserootdesc (descXML, descXMLsize, &data);
|
||||||
|
free (descXML); descXML = 0;
|
||||||
|
GetUPNPUrls (&urls, &data, dev->descURL);
|
||||||
|
}
|
||||||
|
sprintf(buf, "UPnP device found: %s %s LAN address %s", dev->descURL, dev->st, lanaddr);
|
||||||
|
//addDumpInfo(buf);
|
||||||
|
freeUPNPDevlist(devlist);
|
||||||
|
|
||||||
|
if (!urls.controlURL || urls.controlURL[0] == '\0') {
|
||||||
|
sprintf(buf, "controlURL not available, UPnP disabled");
|
||||||
|
//addDumpInfo(buf);
|
||||||
|
//obj->DiscoveredServers();
|
||||||
|
//return false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//obj->DiscoveredServers();
|
||||||
|
int ports[2] = { externalPort, internalPort };
|
||||||
|
ServerSocket::upnp_add_redirect(ports);
|
||||||
|
ServerSocket::enabledUPNP = true;
|
||||||
|
//return true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sprintf(buf, "UPnP device not found.");
|
||||||
|
//addDumpInfo(buf);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"No UPnP devices found.\n");
|
||||||
|
|
||||||
|
//obj->DiscoveredServers();
|
||||||
|
//return false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprintf(buf, "UPnP detection routine disabled by user.");
|
||||||
|
//addDumpInfo(buf);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"UPnP detection routine disabled by user.\n");
|
||||||
|
|
||||||
|
//obj->DiscoveredServers();
|
||||||
|
//return false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveUPNPPortForward(int internalPort, int externalPort) {
|
||||||
|
ServerSocket::upnp_rem_redirect(externalPort);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// This code below handles Universal Plug and Play Router Port Forwarding
|
// This code below handles Universal Plug and Play Router Port Forwarding
|
||||||
@ -1902,7 +1993,7 @@ int ServerSocket::upnp_init(void *param) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerSocket::upnp_add_redirect(int ports[4]) {
|
bool ServerSocket::upnp_add_redirect(int ports[2]) {
|
||||||
char externalIP[16]="";
|
char externalIP[16]="";
|
||||||
char ext_port_str[16]="";
|
char ext_port_str[16]="";
|
||||||
char int_port_str[16]="";
|
char int_port_str[16]="";
|
||||||
@ -1923,16 +2014,16 @@ bool ServerSocket::upnp_add_redirect(int ports[4]) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(ext_port_str, "%d", ports[2]);
|
//sprintf(ext_port_str, "%d", ports[2]);
|
||||||
sprintf(int_port_str, "%d", ports[3]);
|
//sprintf(int_port_str, "%d", ports[3]);
|
||||||
|
|
||||||
r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
|
//r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
|
||||||
ext_port_str, int_port_str, lanaddr, "MegaGlest (FTP) - www.megaglest.org", "TCP", 0);
|
// ext_port_str, int_port_str, lanaddr, "MegaGlest (FTP) - www.megaglest.org", "TCP", 0);
|
||||||
|
|
||||||
if (r != UPNPCOMMAND_SUCCESS) {
|
//if (r != UPNPCOMMAND_SUCCESS) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"AddPortMapping(%s, %s, %s) failed\n", ext_port_str, int_port_str, lanaddr);
|
// SystemFlags::OutputDebug(SystemFlags::debugNetwork,"AddPortMapping(%s, %s, %s) failed\n", ext_port_str, int_port_str, lanaddr);
|
||||||
//return false;
|
//return false;
|
||||||
}
|
//}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -1953,7 +2044,10 @@ void ServerSocket::NETaddRedirects(int ports[4]) {
|
|||||||
// upnp_done = true;
|
// upnp_done = true;
|
||||||
//}
|
//}
|
||||||
//if (upnp) {
|
//if (upnp) {
|
||||||
upnp_add_redirect(ports);
|
int portsA[2] = { ports[0], ports[1] };
|
||||||
|
upnp_add_redirect(portsA);
|
||||||
|
int portsB[2] = { ports[2], ports[3] };
|
||||||
|
upnp_add_redirect(portsB);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user