mirror of https://github.com/mgba-emu/mgba.git
Qt: Add utility for IP address conversion to internal format
This commit is contained in:
parent
9877c1bf1e
commit
817e4d950f
|
@ -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() {
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void setPort(ushort port);
|
||||
void setBindAddress(uint32_t bindAddress);
|
||||
void setBindAddress(const Address&);
|
||||
void listen();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <QVBoxLayout>
|
||||
|
||||
#include "GDBController.h"
|
||||
#include "utils.h"
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
|
@ -77,24 +78,14 @@ void GDBWindow::portChanged(const QString& portString) {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ QString niceSizeFormat(size_t filesize) {
|
|||
}
|
||||
return unit.arg(size, 0, 'f', int(size * 10) % 10 ? 1 : 0);
|
||||
}
|
||||
|
||||
QString nicePlatformFormat(mPlatform platform) {
|
||||
switch (platform) {
|
||||
#ifdef M_CORE_GBA
|
||||
|
@ -37,4 +38,25 @@ QString nicePlatformFormat(mPlatform platform) {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <mgba/core/core.h>
|
||||
#include <mgba-util/socket.h>
|
||||
|
||||
#include <QHostAddress>
|
||||
#include <QRect>
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
|
@ -25,6 +27,8 @@ enum class Endian {
|
|||
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()) {
|
||||
size.setWidth(size.height() * ref.width() / ref.height());
|
||||
|
|
Loading…
Reference in New Issue