Try/catch the DNS decoding
This commit is contained in:
parent
ac8b772060
commit
5d337b2d29
1 changed files with 59 additions and 51 deletions
|
@ -136,69 +136,77 @@ void IppDiscovery::readPendingDatagrams()
|
||||||
sender = QHostAddress(sender.toIPv4Address());
|
sender = QHostAddress(sender.toIPv4Address());
|
||||||
|
|
||||||
quint16 transactionid, flags, questions, answerRRs, authRRs, addRRs;
|
quint16 transactionid, flags, questions, answerRRs, authRRs, addRRs;
|
||||||
resp >> transactionid >> flags >> questions >> answerRRs >> authRRs >> addRRs;
|
|
||||||
|
|
||||||
for(quint16 i = 0; i < questions; i++)
|
try {
|
||||||
{
|
|
||||||
quint16 qtype, qflags;
|
|
||||||
QString qaddr = get_addr(resp).join('.');
|
|
||||||
resp >> qtype >> qflags;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(quint16 i = 0; i < answerRRs; i++)
|
resp >> transactionid >> flags >> questions >> answerRRs >> authRRs >> addRRs;
|
||||||
{
|
|
||||||
quint16 atype, aflags, len;
|
|
||||||
quint32 ttl;
|
|
||||||
|
|
||||||
QString aaddr = get_addr(resp).join('.');
|
for(quint16 i = 0; i < questions; i++)
|
||||||
resp >> atype >> aflags >> ttl >> len;
|
|
||||||
|
|
||||||
quint16 pos_before = resp.pos();
|
|
||||||
if (atype == PTR)
|
|
||||||
{
|
{
|
||||||
QString tmpname = get_addr(resp).join(".");
|
quint16 qtype, qflags;
|
||||||
if(aaddr.endsWith("_ipp._tcp.local"))
|
QString qaddr = get_addr(resp).join('.');
|
||||||
{
|
resp >> qtype >> qflags;
|
||||||
ipp_ptrs.append(tmpname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(atype == TXT)
|
|
||||||
|
for(quint16 i = 0; i < answerRRs; i++)
|
||||||
{
|
{
|
||||||
Bytestream tmp;
|
quint16 atype, aflags, len;
|
||||||
while(resp.pos() < pos_before+len)
|
quint32 ttl;
|
||||||
|
|
||||||
|
QString aaddr = get_addr(resp).join('.');
|
||||||
|
resp >> atype >> aflags >> ttl >> len;
|
||||||
|
|
||||||
|
quint16 pos_before = resp.pos();
|
||||||
|
if (atype == PTR)
|
||||||
{
|
{
|
||||||
resp/resp.getU8() >> tmp;
|
QString tmpname = get_addr(resp).join(".");
|
||||||
if(tmp >>= "rp=")
|
if(aaddr.endsWith("_ipp._tcp.local"))
|
||||||
{
|
{
|
||||||
std::string tmprp;
|
ipp_ptrs.append(tmpname);
|
||||||
tmp/tmp.remaining() >> tmprp;
|
|
||||||
_rps[aaddr] = tmprp.c_str();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else if(atype == TXT)
|
||||||
else if (atype == SRV)
|
{
|
||||||
{
|
Bytestream tmp;
|
||||||
quint16 prio, w, port;
|
while(resp.pos() < pos_before+len)
|
||||||
resp >> prio >> w >> port;
|
{
|
||||||
QString target = get_addr(resp).join(".");
|
resp/resp.getU8() >> tmp;
|
||||||
_ports[aaddr] = port;
|
if(tmp >>= "rp=")
|
||||||
_targets[aaddr] = target;
|
{
|
||||||
}
|
std::string tmprp;
|
||||||
else if(atype == A)
|
tmp/tmp.remaining() >> tmprp;
|
||||||
{
|
_rps[aaddr] = tmprp.c_str();
|
||||||
quint32 addr;
|
}
|
||||||
resp >> addr;
|
}
|
||||||
QHostAddress haddr(addr);
|
}
|
||||||
_AAs.insert(aaddr, haddr.toString());
|
else if (atype == SRV)
|
||||||
}
|
{
|
||||||
else
|
quint16 prio, w, port;
|
||||||
{
|
resp >> prio >> w >> port;
|
||||||
resp += len;
|
QString target = get_addr(resp).join(".");
|
||||||
}
|
_ports[aaddr] = port;
|
||||||
Q_ASSERT(resp.pos() == pos_before+len);
|
_targets[aaddr] = target;
|
||||||
|
}
|
||||||
|
else if(atype == A)
|
||||||
|
{
|
||||||
|
quint32 addr;
|
||||||
|
resp >> addr;
|
||||||
|
QHostAddress haddr(addr);
|
||||||
|
_AAs.insert(aaddr, haddr.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resp += len;
|
||||||
|
}
|
||||||
|
Q_ASSERT(resp.pos() == pos_before+len);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(std::exception e)
|
||||||
|
{
|
||||||
|
qDebug() << e.what();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "new ipp ptrs" << ipp_ptrs;
|
qDebug() << "new ipp ptrs" << ipp_ptrs;
|
||||||
qDebug() << "ipp ptrs" << _ipp;
|
qDebug() << "ipp ptrs" << _ipp;
|
||||||
qDebug() << "rps" << _rps;
|
qDebug() << "rps" << _rps;
|
||||||
|
|
Loading…
Reference in a new issue