mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 10:22:55 +00:00
implement option to not output the scope from QHostAddress::toString()
the people behind the old QHostAddress implementation fucked up, fixing it is a piece of cake tho Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
64a1e01cac
commit
cad6c377aa
5 changed files with 24 additions and 13 deletions
|
@ -3,7 +3,7 @@
|
|||
# https://wiki.archlinux.org/index.php/Arch_package_guidelines
|
||||
|
||||
pkgname=katie-git
|
||||
pkgver=4.14.0.r8182.f99b0e1ad
|
||||
pkgver=4.14.0.r8194.64a1e01ca
|
||||
pkgrel=1
|
||||
pkgdesc='C++ toolkit derived from the Qt 4.8 framework'
|
||||
arch=('i486' 'i686' 'pentium4' 'x86_64' 'arm')
|
||||
|
|
|
@ -324,11 +324,13 @@ QAbstractSocket::NetworkLayerProtocol QHostAddress::protocol() const
|
|||
|
||||
For example, if the address is the IPv4 address 127.0.0.1, the
|
||||
returned string is "127.0.0.1". For IPv6 the string format will
|
||||
follow the RFC5952 recommendation.
|
||||
follow the RFC5952 recommendation only if \a options includes
|
||||
QHostAddress::RemoveScope.
|
||||
*/
|
||||
QByteArray QHostAddress::toString() const
|
||||
QByteArray QHostAddress::toString(FormattingOptions options) const
|
||||
{
|
||||
if (d->protocol == QAbstractSocket::IPv6Protocol && !d->scopeId.isEmpty()) {
|
||||
if (!(options & QHostAddress::RemoveScope) &&
|
||||
d->protocol == QAbstractSocket::IPv6Protocol && !d->scopeId.isEmpty()) {
|
||||
return d->ipString + addrscopeseparator + d->scopeId;
|
||||
}
|
||||
return d->ipString;
|
||||
|
|
|
@ -45,6 +45,12 @@ public:
|
|||
AnyIPv6
|
||||
};
|
||||
|
||||
enum FormattingOption {
|
||||
None = 0x0,
|
||||
RemoveScope = 0x1,
|
||||
};
|
||||
Q_DECLARE_FLAGS(FormattingOptions, FormattingOption)
|
||||
|
||||
QHostAddress();
|
||||
explicit QHostAddress(const sockaddr *sockaddr);
|
||||
explicit QHostAddress(const QByteArray &address);
|
||||
|
@ -60,7 +66,7 @@ public:
|
|||
|
||||
QAbstractSocket::NetworkLayerProtocol protocol() const;
|
||||
|
||||
QByteArray toString() const;
|
||||
QByteArray toString(FormattingOptions options = None) const;
|
||||
|
||||
QByteArray scopeId() const;
|
||||
void setScopeId(const QByteArray &id);
|
||||
|
@ -74,6 +80,7 @@ public:
|
|||
private:
|
||||
QScopedPointer<QHostAddressPrivate> d;
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QHostAddress::FormattingOptions)
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
Q_NETWORK_EXPORT QDebug operator<<(QDebug, const QHostAddress &);
|
||||
|
|
|
@ -66,7 +66,7 @@ QHostInfo QHostInfoPrivate::fromName(const QString &hostName)
|
|||
|
||||
QHostAddress address;
|
||||
if (address.setAddress(hostName.toLatin1())) {
|
||||
const QByteArray addressStr = address.toString();
|
||||
const QByteArray addressStr = address.toString(QHostAddress::RemoveScope);
|
||||
#if defined(QHOSTINFO_DEBUG)
|
||||
qDebug("QHostInfoPrivate::fromName(%s) looking up address...",
|
||||
hostName.toLatin1().constData());
|
||||
|
@ -129,8 +129,10 @@ QHostInfo QHostInfoPrivate::fromName(const QString &hostName)
|
|||
results.d->errorStr = QString::fromLocal8Bit(::gai_strerror(result));
|
||||
}
|
||||
|
||||
if (results.hostName().isEmpty())
|
||||
if (results.hostName().isEmpty()) {
|
||||
// hostname is not exactly valid with scope, internally it is handled tho
|
||||
results.d->hostName = address.toString();
|
||||
}
|
||||
results.d->addrs.append(address);
|
||||
#if defined(QHOSTINFO_DEBUG)
|
||||
dumpHostResult(hostName, results);
|
||||
|
|
|
@ -275,7 +275,7 @@ bool QAbstractSocketEnginePrivate::nativeConnect(const QHostAddress &addr, quint
|
|||
qDebug("QAbstractSocketEnginePrivate::nativeConnect() : %d ", socketDescriptor);
|
||||
#endif
|
||||
|
||||
const QByteArray addrStr = addr.toString();
|
||||
const QByteArray addrStr = addr.toString(QHostAddress::RemoveScope);
|
||||
|
||||
struct sockaddr_in sockAddrIPv4;
|
||||
struct sockaddr *sockAddrPtr = 0;
|
||||
|
@ -386,7 +386,7 @@ bool QAbstractSocketEnginePrivate::nativeConnect(const QHostAddress &addr, quint
|
|||
|
||||
bool QAbstractSocketEnginePrivate::nativeBind(const QHostAddress &address, quint16 port)
|
||||
{
|
||||
const QByteArray addrStr = address.toString();
|
||||
const QByteArray addrStr = address.toString(QHostAddress::RemoveScope);
|
||||
|
||||
struct sockaddr_in sockAddrIPv4;
|
||||
struct sockaddr *sockAddrPtr = 0;
|
||||
|
@ -516,7 +516,7 @@ static bool multicastMembershipHelper(QAbstractSocketEnginePrivate *d,
|
|||
const QHostAddress &groupAddress,
|
||||
const QNetworkInterface &interface)
|
||||
{
|
||||
const QByteArray groupAddressStr = groupAddress.toString();
|
||||
const QByteArray groupAddressStr = groupAddress.toString(QHostAddress::RemoveScope);
|
||||
|
||||
int level = 0;
|
||||
int sockOpt = 0;
|
||||
|
@ -553,7 +553,7 @@ static bool multicastMembershipHelper(QAbstractSocketEnginePrivate *d,
|
|||
QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
|
||||
if (!addressEntries.isEmpty()) {
|
||||
QHostAddress firstIP = addressEntries.first().ip();
|
||||
const QByteArray firstIPStr = firstIP.toString();
|
||||
const QByteArray firstIPStr = firstIP.toString(QHostAddress::RemoveScope);
|
||||
struct in_addr ia;
|
||||
inet_pton(AF_INET, firstIPStr.constData(), &ia);
|
||||
mreq4.imr_interface = ia;
|
||||
|
@ -671,7 +671,7 @@ bool QAbstractSocketEnginePrivate::nativeSetMulticastInterface(const QNetworkInt
|
|||
const QNetworkAddressEntry &entry = entries.at(i);
|
||||
const QHostAddress &ip = entry.ip();
|
||||
if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
const QByteArray ipStr = ip.toString();
|
||||
const QByteArray ipStr = ip.toString(QHostAddress::RemoveScope);
|
||||
inet_pton(AF_INET, ipStr.constData(), &v);
|
||||
int r = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, &v, sizeof(v));
|
||||
if (r != -1)
|
||||
|
@ -783,7 +783,7 @@ qint64 QAbstractSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 ma
|
|||
qint64 QAbstractSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 len,
|
||||
const QHostAddress &host, quint16 port)
|
||||
{
|
||||
const QByteArray hostStr = host.toString();
|
||||
const QByteArray hostStr = host.toString(QHostAddress::RemoveScope);
|
||||
|
||||
struct sockaddr_in sockAddrIPv4;
|
||||
struct sockaddr *sockAddrPtr = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue