| 1368 | } |
| 1369 | |
| 1370 | bool HyperAPI::isLocal(QString hostname) |
| 1371 | { |
| 1372 | QHostAddress address(hostname); |
| 1373 | |
| 1374 | if (QAbstractSocket::IPv4Protocol != address.protocol() && |
| 1375 | QAbstractSocket::IPv6Protocol != address.protocol()) |
| 1376 | { |
| 1377 | auto result = QHostInfo::fromName(hostname); |
| 1378 | if (result.error() == QHostInfo::HostInfoError::NoError) |
| 1379 | { |
| 1380 | QList<QHostAddress> list = result.addresses(); |
| 1381 | for (int x = 1; x >= 0; x--) |
| 1382 | foreach(const QHostAddress& l, list) |
| 1383 | if (l.protocol() == (x > 0) ? QAbstractSocket::IPv4Protocol : QAbstractSocket::IPv6Protocol) |
| 1384 | { |
| 1385 | address = l; |
| 1386 | x = 0; |
| 1387 | break; |
| 1388 | } |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | if (QAbstractSocket::IPv4Protocol == address.protocol()) |
| 1393 | { |
| 1394 | quint32 adr = address.toIPv4Address(); |
| 1395 | uint8_t a = adr >> 24; |
| 1396 | uint8_t b = (adr >> 16) & 0xff; |
| 1397 | |
| 1398 | Debug(_log, "IP4 prefix: %i.%i", a, b); |
| 1399 | |
| 1400 | return ((a == 192 && b == 168) || (a == 10) || (a == 172 && b >= 16 && b <32)); |
| 1401 | } |
| 1402 | |
| 1403 | else if (QAbstractSocket::IPv6Protocol == address.protocol()) |
| 1404 | { |
| 1405 | auto i = address.toString(); |
| 1406 | |
| 1407 | Debug(_log, "IP6 prefix: %s", QSTRING_CSTR(i.left(4))); |
| 1408 | |
| 1409 | return i.indexOf("fd") == 0 || i.indexOf("fe80") == 0; |
| 1410 | } |
| 1411 | |
| 1412 | return false; |
| 1413 | } |
| 1414 | |
| 1415 | void HyperAPI::handleSysInfoCommand(const QJsonObject&, const QString& command, int tan) |
| 1416 | { |