add IPv6 support for RemoteControl

To specify IP(v4/v6) address for RemoteControl port,
add Address parameter in [RemoteControl] section to MMDVM.ini.

Different from other Address(es), the default IP address of RemoteControl
is 127.0.0.1 for security.
This commit is contained in:
SASANO Takayoshi 2020-04-11 13:12:19 +09:00
parent 88bbb0cd0f
commit 5df1fe551f
6 changed files with 18 additions and 5 deletions

View file

@ -250,6 +250,7 @@ m_mobileGPSEnabled(false),
m_mobileGPSAddress(),
m_mobileGPSPort(0U),
m_remoteControlEnabled(false),
m_remoteControlAddress("127.0.0.1"),
m_remoteControlPort(0U)
{
}
@ -838,6 +839,8 @@ bool CConf::read()
} else if (section == SECTION_REMOTE_CONTROL) {
if (::strcmp(key, "Enable") == 0)
m_remoteControlEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Address") == 0)
m_remoteControlAddress = value;
else if (::strcmp(key, "Port") == 0)
m_remoteControlPort = (unsigned int)::atoi(value);
}
@ -1794,6 +1797,11 @@ bool CConf::getRemoteControlEnabled() const
return m_remoteControlEnabled;
}
std::string CConf::getRemoteControlAddress() const
{
return m_remoteControlAddress;
}
unsigned int CConf::getRemoteControlPort() const
{
return m_remoteControlPort;

2
Conf.h
View file

@ -276,6 +276,7 @@ public:
// The Remote Control section
bool getRemoteControlEnabled() const;
std::string getRemoteControlAddress() const;
unsigned int getRemoteControlPort() const;
private:
@ -497,6 +498,7 @@ private:
unsigned int m_mobileGPSPort;
bool m_remoteControlEnabled;
std::string m_remoteControlAddress;
unsigned int m_remoteControlPort;
};

View file

@ -257,4 +257,5 @@ Port=7834
[Remote Control]
Enable=0
Address=127.0.0.1
Port=7642

View file

@ -606,12 +606,14 @@ int CMMDVMHost::run()
bool remoteControlEnabled = m_conf.getRemoteControlEnabled();
if (remoteControlEnabled) {
std::string address = m_conf.getRemoteControlAddress();
unsigned int port = m_conf.getRemoteControlPort();
LogInfo("Remote Control Parameters");
LogInfo(" Address: %s", address.c_str());
LogInfo(" Port: %u", port);
m_remoteControl = new CRemoteControl(port);
m_remoteControl = new CRemoteControl(address, port);
ret = m_remoteControl->open();
if (!ret) {

View file

@ -29,8 +29,8 @@ const unsigned int PAGE_ARGS = 3U;
const unsigned int BUFFER_LENGTH = 100U;
CRemoteControl::CRemoteControl(unsigned int port) :
m_socket(port),
CRemoteControl::CRemoteControl(const std::string address, unsigned int port) :
m_socket(address, port),
m_command(RCD_NONE),
m_args()
{
@ -43,7 +43,7 @@ CRemoteControl::~CRemoteControl()
bool CRemoteControl::open()
{
return m_socket.open(AF_INET); /* XXX IPv4 only */
return m_socket.open();
}
REMOTE_COMMAND CRemoteControl::getCommand()

View file

@ -38,7 +38,7 @@ enum REMOTE_COMMAND {
class CRemoteControl {
public:
CRemoteControl(unsigned int port);
CRemoteControl(const std::string address, unsigned int port);
~CRemoteControl();
bool open();