all repos — mgba @ 817e4d950f3689603d211d8a8b4ccb5d72ee40ca

mGBA Game Boy Advance Emulator

Qt: Add utility for IP address conversion to internal format
Vicki Pfau vi@endrift.com
Mon, 22 Feb 2021 18:20:51 -0800
commit

817e4d950f3689603d211d8a8b4ccb5d72ee40ca

parent

9877c1bf1e969a7d7441d843b57205acc71cbed2

M src/platform/qt/GDBController.cppsrc/platform/qt/GDBController.cpp

@@ -11,7 +11,7 @@ using namespace QGBA;

GDBController::GDBController(QObject* parent) : DebuggerController(&m_gdbStub.d, parent) - , m_bindAddress({ IPV4, 0 }) + , m_bindAddress({ IPV4, {0} }) { GDBStubCreate(&m_gdbStub); }

@@ -28,9 +28,8 @@ void GDBController::setPort(ushort port) {

m_port = port; } -void GDBController::setBindAddress(uint32_t bindAddress) { - m_bindAddress.version = IPV4; - m_bindAddress.ipv4 = htonl(bindAddress); +void GDBController::setBindAddress(const Address& address) { + m_bindAddress = address; } void GDBController::listen() {
M src/platform/qt/GDBController.hsrc/platform/qt/GDBController.h

@@ -27,7 +27,7 @@ bool isAttached();

public slots: void setPort(ushort port); - void setBindAddress(uint32_t bindAddress); + void setBindAddress(const Address&); void listen(); signals:
M src/platform/qt/GDBWindow.cppsrc/platform/qt/GDBWindow.cpp

@@ -15,6 +15,7 @@ #include <QHBoxLayout>

#include <QVBoxLayout> #include "GDBController.h" +#include "utils.h" using namespace QGBA;

@@ -77,24 +78,14 @@ }

} void GDBWindow::bindAddressChanged(const QString& bindAddressString) { - bool ok = false; - QStringList parts = bindAddressString.split('.'); - if (parts.length() != 4) { + QHostAddress qaddress; + Address address; + + if (!qaddress.setAddress(bindAddressString)) { return; } - int i; - uint32_t address = 0; - for (i = 0; i < 4; ++i) { - ushort octet = parts[i].toUShort(&ok); - if (!ok) { - return; - } - if (octet > 0xFF) { - return; - } - address <<= 8; - address += octet; - } + + convertAddress(&qaddress, &address); m_gdbController->setBindAddress(address); }
M src/platform/qt/utils.cppsrc/platform/qt/utils.cpp

@@ -22,6 +22,7 @@ unit = QObject::tr("%1 MiB");

} return unit.arg(size, 0, 'f', int(size * 10) % 10 ? 1 : 0); } + QString nicePlatformFormat(mPlatform platform) { switch (platform) { #ifdef M_CORE_GBA

@@ -35,6 +36,27 @@ #endif

default: return QObject::tr("?"); } +} + +bool convertAddress(const QHostAddress* input, Address* output) { + if (input->isNull()) { + return false; + } + Q_IPV6ADDR ipv6; + switch (input->protocol()) { + case QAbstractSocket::IPv4Protocol: + output->version = IPV4; + output->ipv4 = input->toIPv4Address(); + break; + case QAbstractSocket::IPv6Protocol: + output->version = IPV6; + ipv6 = input->toIPv6Address(); + memcpy(output->ipv6, &ipv6, 16); + break; + default: + return false; + } + return true; } }
M src/platform/qt/utils.hsrc/platform/qt/utils.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#pragma once #include <mgba/core/core.h> +#include <mgba-util/socket.h> +#include <QHostAddress> #include <QRect> #include <QSize> #include <QString>

@@ -24,6 +26,8 @@ };

QString niceSizeFormat(size_t filesize); QString nicePlatformFormat(mPlatform platform); + +bool convertAddress(const QHostAddress* input, Address* output); inline void lockAspectRatio(const QSize& ref, QSize& size) { if (size.width() * ref.height() > size.height() * ref.width()) {