19 #include <QStringList>
20 #include <QNetworkInterface>
28 #include "libmythbase/mythversion.h"
34 QHostAddress::parseSubnet(
"fe80::/10");
49 const QHostAddress& peerAddress,
53 Task(
"UPnpSearchTask"),
54 m_nServicePort(nServicePort),
55 m_peerAddress(peerAddress),
56 m_nPeerPort(nPeerPort),
57 m_sST(std::move(sST)),
58 m_sUDN(std::move(sUDN))
73 if (( sUDN.length() > 0) && ( sUDN != sST ))
74 sUSN = sUDN +
"::" + sST;
80 QString sData = QString (
"CACHE-CONTROL: max-age=%1\r\n"
86 "Content-Length: 0\r\n\r\n" )
94 LOG(VB_UPNP, LOG_DEBUG, QString(
"UPnpSearchTask::SendMsg : %1 : %2 ")
95 .arg(sST) .arg(sUSN));
97 LOG(VB_UPNP, LOG_DEBUG,
98 QString(
"UPnpSearchTask::SendMsg m_peerAddress = %1 Port=%2")
107 QList<QNetworkInterface> IFs = QNetworkInterface::allInterfaces();
108 for (
const auto & qni : std::as_const(IFs))
110 QList<QNetworkAddressEntry> netAddressList = qni.addressEntries();
111 for (
const auto & netAddr : std::as_const(netAddressList))
113 QString ip_subnet = QString(
"%1/%2").arg(netAddr.ip().toString()).arg(netAddr.prefixLength());
114 QPair<QHostAddress, int> subnet = QHostAddress::parseSubnet(ip_subnet);
116 LOG(VB_UPNP, LOG_DEBUG, QString(
"UPnpSearchTask::SendMsg : IP: [%1], Found network [%2], relevant to peer [%3]")
117 .arg(netAddr.ip().toString(), subnet.first.toString(),
m_peerAddress.toString()));
120 QHostAddress ip = netAddr.ip();
124 ip.setScopeId(QString());
127 if (ip.protocol() == QAbstractSocket::IPv6Protocol)
128 ipaddress =
"[" + ip.toString() +
"]";
130 ipaddress = ip.toString();
132 QString sHeader = QString (
"HTTP/1.1 200 OK\r\n"
133 "LOCATION: http://%1:%2/getDeviceDesc\r\n" )
138 QString sPacket = sHeader + sData;
139 QByteArray scPacket = sPacket.toUtf8();
145 pSocket->writeBlock( scPacket, scPacket.length(),
m_peerAddress,
148 std::this_thread::sleep_for(std::chrono::milliseconds(
MythRandom(0, 250)));
150 pSocket->writeBlock( scPacket, scPacket.length(),
m_peerAddress,
163 auto *pSocket =
new MSocketDevice( MSocketDevice::Datagram );
177 if ((
m_sST ==
"upnp:rootdevice") || (
m_sST ==
"ssdp:all" ))
181 if (
m_sST ==
"ssdp:all")