summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormethodus <methodus@web.de>2013-01-02 21:26:22 +0100
committermethodus <methodus@web.de>2013-01-02 21:26:22 +0100
commit1cd3c746a1d3b8d0a5eeb100ea582ff04cc4a454 (patch)
treed39d6249f474c930bed8001a0b0a9443e67db2e2
parentf69c0682c565477ac4632a86b0ebdc9c2ca3148a (diff)
downloadvdr-plugin-upnp-1cd3c746a1d3b8d0a5eeb100ea582ff04cc4a454.tar.gz
vdr-plugin-upnp-1cd3c746a1d3b8d0a5eeb100ea582ff04cc4a454.tar.bz2
Fixed crash if no network connection is available. Plugin will then listen on localhost
-rw-r--r--common/tools.cpp6
-rw-r--r--server/server.cpp6
2 files changed, 8 insertions, 4 deletions
diff --git a/common/tools.cpp b/common/tools.cpp
index c18d21e..d46e8c1 100644
--- a/common/tools.cpp
+++ b/common/tools.cpp
@@ -63,7 +63,11 @@ string GetAddressByInterface(string Interface){
return address;
}
string GetNetworkInterfaceByIndex(int Index, bool skipLoop){
- return GetNetworkInterfaces(skipLoop)[Index];
+ StringVector interfaces = GetNetworkInterfaces(skipLoop);
+ if(interfaces.size() < 0)
+ return interfaces[Index];
+ else
+ return string();
}
StringVector GetNetworkInterfaces(bool skipLoop){
diff --git a/server/server.cpp b/server/server.cpp
index 2bac18a..f8c5515 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -180,7 +180,7 @@ bool cMediaServer::Initialize(){
? mCurrentConfiguration.address
: tools::GetAddressByInterface(mCurrentConfiguration.interface);
- if(address.empty() || !address.compare("0.0.0.0")){
+ if(address.empty() || address.compare("0.0.0.0") == 0){
address = tools::GetAddressByInterface(tools::GetNetworkInterfaceByIndex(0, true));
}
@@ -192,9 +192,9 @@ bool cMediaServer::Initialize(){
int ret = 0;
- LOG(1, "Initializing UPnP media server on %s:%d", address.c_str(), port);
+ LOG(1, "Initializing UPnP media server on %s:%d", address.empty()?"0":address.c_str(), port);
- ret = UpnpInit(address.c_str(), mCurrentConfiguration.port);
+ ret = UpnpInit(address.empty()?"127.0.0.1":address.c_str(), mCurrentConfiguration.port);
if(ret != UPNP_E_SUCCESS && ret != UPNP_E_INIT){
esyslog("UPnP\tFailed to initialise UPnP media server. Error code: %d", ret);