diff options
author | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2009-02-18 00:19:32 +0100 |
---|---|---|
committer | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2009-02-18 00:19:32 +0100 |
commit | e3343f602dfe288afa1f027563d307d049d95c1e (patch) | |
tree | 27d213be41939ebcb57efafba3d79221556896bc | |
parent | f9738cfe51da2e3dd0533398e51079f8487b7ff5 (diff) | |
download | vdr-plugin-live-e3343f602dfe288afa1f027563d307d049d95c1e.tar.gz vdr-plugin-live-e3343f602dfe288afa1f027563d307d049d95c1e.tar.bz2 |
Fixed the need to add an --ip parameter on the live command line if
the host had no IPv6 support in the kernel (or module).
Don't abort operation if one of the given ips fails at bind call.
Abort only if every bind call fails.
-rw-r--r-- | setup.cpp | 39 | ||||
-rw-r--r-- | tntconfig.cpp | 13 |
2 files changed, 39 insertions, 13 deletions
@@ -155,25 +155,40 @@ bool Setup::CheckServerSslPort() } #endif +namespace { + struct IpValidator + { + bool operator() (string const & ip) + { + struct in6_addr buf; + struct in_addr buf4; + + bool valid = inet_aton(ip.c_str(), &buf4) || inet_pton(AF_INET6, ip.c_str(), &buf); + + if (!valid) { + esyslog( "ERROR: live server ip %s is not a valid ip address", ip.c_str()); + cerr << "ERROR: live server ip '" << ip << "' is not a valid ip address" << endl; + } + return valid; + } + }; +} + bool Setup::CheckServerIps() { - struct in6_addr buf; - if ( m_serverIps.empty() ) { + // add a default IPv4 listener address + m_serverIps.push_back( "0.0.0.0" ); + // and be prepared for IPv6 only hosts. m_serverIps.push_back( "::" ); + // we assume these are ok :) return true; } - for ( IpList::const_iterator ip = m_serverIps.begin(); ip != m_serverIps.end(); ++ip ) { - if ( inet_addr( ip->c_str() ) == static_cast< in_addr_t >( -1 ) ) { - if ( ! inet_pton( AF_INET6, ip->c_str(), &buf ) ) { - esyslog( "ERROR: live server ip %s is not a valid ip address", ip->c_str() ); - cerr << "ERROR: live server ip " << *ip << " is not a valid ip address" << endl; - return false; - } - } - } - return true; + IpList::iterator i = partition(m_serverIps.begin(), m_serverIps.end(), IpValidator()); + m_serverIps.erase(i, m_serverIps.end()); + + return !m_serverIps.empty(); } std::string const Setup::GetMD5HashAdminPassword() const diff --git a/tntconfig.cpp b/tntconfig.cpp index 23943a5..d35dad4 100644 --- a/tntconfig.cpp +++ b/tntconfig.cpp @@ -252,8 +252,19 @@ namespace vdrlive { Setup::IpList const& ips = LiveSetup().GetServerIps(); int port = LiveSetup().GetServerPort(); + size_t listenFailures = 0; for ( Setup::IpList::const_iterator ip = ips.begin(); ip != ips.end(); ++ip ) { - app.listen(*ip, port); + try { + app.listen(*ip, port); + } + catch (exception const & ex) { + esyslog("ERROR: live ip = %s is invalid: exception = %s", ip->c_str(), ex.what()); + if (++listenFailures == ips.size()) { + // if no listener was initialized we throw at + // least the last exception to the next layer. + throw; + } + } } #if TNTSSLSUPPORT |