Skip to content

Commit 0075bc5

Browse files
authored
Merge pull request #980 from soyersoyer/fixnetip
InitNetwork IPAddress related fixes
2 parents f0c57eb + a52e1a9 commit 0075bc5

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

src/config.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,13 @@ void CConfig::Load (void)
206206
m_bNetworkDHCP = m_Properties.GetNumber ("NetworkDHCP", 0) != 0;
207207
m_NetworkType = m_Properties.GetString ("NetworkType", "wlan");
208208
m_NetworkHostname = m_Properties.GetString ("NetworkHostname", "MiniDexed");
209-
m_INetworkIPAddress = m_Properties.GetIPAddress("NetworkIPAddress") != 0;
210-
m_INetworkSubnetMask = m_Properties.GetIPAddress("NetworkSubnetMask") != 0;
211-
m_INetworkDefaultGateway = m_Properties.GetIPAddress("NetworkDefaultGateway") != 0;
209+
if (const u8 *pIP = m_Properties.GetIPAddress("NetworkIPAddress")) m_INetworkIPAddress.Set (pIP);
210+
if (const u8 *pIP = m_Properties.GetIPAddress("NetworkSubnetMask")) m_INetworkSubnetMask.Set (pIP);
211+
if (const u8 *pIP = m_Properties.GetIPAddress("NetworkDefaultGateway")) m_INetworkDefaultGateway.Set (pIP);
212212
m_bSyslogEnabled = m_Properties.GetNumber ("NetworkSyslogEnabled", 0) != 0;
213-
m_INetworkDNSServer = m_Properties.GetIPAddress("NetworkDNSServer") != 0;
213+
if (const u8 *pIP = m_Properties.GetIPAddress("NetworkDNSServer")) m_INetworkDNSServer.Set (pIP);
214214
m_bNetworkFTPEnabled = m_Properties.GetNumber("NetworkFTPEnabled", 0) != 0;
215-
216-
const u8 *pSyslogServerIP = m_Properties.GetIPAddress ("NetworkSyslogServerIPAddress");
217-
if (pSyslogServerIP)
218-
{
219-
m_INetworkSyslogServerIPAddress.Set (pSyslogServerIP);
220-
}
215+
if (const u8 *pIP = m_Properties.GetIPAddress ("NetworkSyslogServerIPAddress")) m_INetworkSyslogServerIPAddress.Set (pIP);
221216

222217
m_nMasterVolume = m_Properties.GetNumber ("MasterVolume", 64);
223218
}
@@ -764,22 +759,22 @@ const char *CConfig::GetNetworkHostname (void) const
764759
return m_NetworkHostname.c_str();
765760
}
766761

767-
CIPAddress CConfig::GetNetworkIPAddress (void) const
762+
const CIPAddress& CConfig::GetNetworkIPAddress (void) const
768763
{
769764
return m_INetworkIPAddress;
770765
}
771766

772-
CIPAddress CConfig::GetNetworkSubnetMask (void) const
767+
const CIPAddress& CConfig::GetNetworkSubnetMask (void) const
773768
{
774769
return m_INetworkSubnetMask;
775770
}
776771

777-
CIPAddress CConfig::GetNetworkDefaultGateway (void) const
772+
const CIPAddress& CConfig::GetNetworkDefaultGateway (void) const
778773
{
779774
return m_INetworkDefaultGateway;
780775
}
781776

782-
CIPAddress CConfig::GetNetworkDNSServer (void) const
777+
const CIPAddress& CConfig::GetNetworkDNSServer (void) const
783778
{
784779
return m_INetworkDNSServer;
785780
}
@@ -789,7 +784,7 @@ bool CConfig::GetSyslogEnabled (void) const
789784
return m_bSyslogEnabled;
790785
}
791786

792-
CIPAddress CConfig::GetNetworkSyslogServerIPAddress (void) const
787+
const CIPAddress& CConfig::GetNetworkSyslogServerIPAddress (void) const
793788
{
794789
return m_INetworkSyslogServerIPAddress;
795790
}

src/config.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ class CConfig // Configuration for MiniDexed
247247
bool GetNetworkDHCP (void) const;
248248
const char *GetNetworkType (void) const;
249249
const char *GetNetworkHostname (void) const;
250-
CIPAddress GetNetworkIPAddress (void) const;
251-
CIPAddress GetNetworkSubnetMask (void) const;
252-
CIPAddress GetNetworkDefaultGateway (void) const;
253-
CIPAddress GetNetworkDNSServer (void) const;
250+
const CIPAddress& GetNetworkIPAddress (void) const;
251+
const CIPAddress& GetNetworkSubnetMask (void) const;
252+
const CIPAddress& GetNetworkDefaultGateway (void) const;
253+
const CIPAddress& GetNetworkDNSServer (void) const;
254254
bool GetSyslogEnabled (void) const;
255-
CIPAddress GetNetworkSyslogServerIPAddress (void) const;
255+
const CIPAddress& GetNetworkSyslogServerIPAddress (void) const;
256256
bool GetNetworkFTPEnabled (void) const;
257257

258258
private:

src/minidexed.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,7 @@ void CMiniDexed::UpdateNetwork()
23192319
if (m_pConfig->GetSyslogEnabled())
23202320
{
23212321
LOGNOTE ("Syslog server is enabled in configuration");
2322-
CIPAddress ServerIP = m_pConfig->GetNetworkSyslogServerIPAddress();
2322+
const CIPAddress& ServerIP = m_pConfig->GetNetworkSyslogServerIPAddress();
23232323
if (ServerIP.IsSet () && !ServerIP.IsNull ())
23242324
{
23252325
static const u16 usServerPort = 8514;
@@ -2416,18 +2416,31 @@ bool CMiniDexed::InitNetwork()
24162416

24172417
if (NetDeviceType != NetDeviceTypeUnknown)
24182418
{
2419-
LOGNOTE("CMiniDexed::InitNetwork: Creating CNetSubSystem");
24202419
if (m_pConfig->GetNetworkDHCP())
2420+
{
2421+
LOGNOTE("CMiniDexed::InitNetwork: Creating CNetSubSystem with DHCP (Hostname: %s)", m_pConfig->GetNetworkHostname());
24212422
m_pNet = new CNetSubSystem(0, 0, 0, 0, m_pConfig->GetNetworkHostname(), NetDeviceType);
2422-
else
2423+
}
2424+
else if (m_pConfig->GetNetworkIPAddress().IsSet() && m_pConfig->GetNetworkSubnetMask().IsSet())
2425+
{
2426+
CString IPString, SubnetString;
2427+
m_pConfig->GetNetworkIPAddress().Format (&IPString);
2428+
m_pConfig->GetNetworkSubnetMask().Format (&SubnetString);
2429+
LOGNOTE("CMiniDexed::InitNetwork: Creating CNetSubSystem with IP: %s / %s", (const char*)IPString, (const char*)SubnetString);
24232430
m_pNet = new CNetSubSystem(
24242431
m_pConfig->GetNetworkIPAddress().Get(),
24252432
m_pConfig->GetNetworkSubnetMask().Get(),
2426-
m_pConfig->GetNetworkDefaultGateway().Get(),
2427-
m_pConfig->GetNetworkDNSServer().Get(),
2433+
m_pConfig->GetNetworkDefaultGateway().IsSet() ? m_pConfig->GetNetworkDefaultGateway().Get() : 0,
2434+
m_pConfig->GetNetworkDNSServer().IsSet() ? m_pConfig->GetNetworkDNSServer().Get() : 0,
24282435
m_pConfig->GetNetworkHostname(),
2429-
NetDeviceType
2430-
);
2436+
NetDeviceType);
2437+
}
2438+
else
2439+
{
2440+
LOGNOTE ("CMiniDexed::InitNetwork: Neither DHCP nor IP address/subnet mask is set, using DHCP (Hostname: %s)", m_pConfig->GetNetworkHostname());
2441+
m_pNet = new CNetSubSystem(0, 0, 0, 0, m_pConfig->GetNetworkHostname(), NetDeviceType);
2442+
}
2443+
24312444
if (!m_pNet || !m_pNet->Initialize(false)) // Check if m_pNet allocation succeeded
24322445
{
24332446
LOGERR("CMiniDexed::InitNetwork: Failed to initialize network subsystem");

0 commit comments

Comments
 (0)