mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
LedUdpDevice now tries to parse the "host" as an IP address before trying to DNS resolve it (#205)
This commit is contained in:
parent
a6bf58c21e
commit
9cc3a2de2e
@ -30,13 +30,24 @@ LedUdpDevice::~LedUdpDevice()
|
|||||||
|
|
||||||
bool LedUdpDevice::setConfig(const Json::Value &deviceConfig)
|
bool LedUdpDevice::setConfig(const Json::Value &deviceConfig)
|
||||||
{
|
{
|
||||||
|
if (_address.setAddress( QString::fromStdString(deviceConfig["host"].asString()) ) )
|
||||||
|
{
|
||||||
|
Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||||
QHostInfo info = QHostInfo::fromName( QString::fromStdString(deviceConfig["host"].asString()) );
|
QHostInfo info = QHostInfo::fromName( QString::fromStdString(deviceConfig["host"].asString()) );
|
||||||
if (info.addresses().isEmpty())
|
if (info.addresses().isEmpty())
|
||||||
{
|
{
|
||||||
|
Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||||
throw std::runtime_error("invalid target address");
|
throw std::runtime_error("invalid target address");
|
||||||
}
|
}
|
||||||
|
Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||||
_address = info.addresses().first();
|
_address = info.addresses().first();
|
||||||
|
}
|
||||||
_port = deviceConfig["port"].asUInt();
|
_port = deviceConfig["port"].asUInt();
|
||||||
|
Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -46,7 +57,7 @@ int LedUdpDevice::open()
|
|||||||
QHostAddress localAddress = QHostAddress::Any;
|
QHostAddress localAddress = QHostAddress::Any;
|
||||||
quint16 localPort = 0;
|
quint16 localPort = 0;
|
||||||
|
|
||||||
WarningIf( !_udpSocket->bind(localAddress, localPort), _log, "Couldnt bind local address: %s", strerror(errno));
|
WarningIf( !_udpSocket->bind(localAddress, localPort), _log, "Could not bind local address: %s", strerror(errno));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user