Commit daec307b authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

smb: use prettyname.kio-discovery-wsd for hostname of wsdiscoveries

previously we simply used the ip address. this is fairly awkward though.
instead try to deduce a resolvable host name from the pretty name.

at discovery time we now mark wsdiscovieres for special handling

at listDir time we then attempt to resolve the name.local and if that
fails strip the .local to get the presumed LLMNR/netbios name. this means
the (first) listDir may be slower while we try to find a working hostname
but discovery is still as fast as possible.

Test Plan: wsdd on linux server resolves as expected, wsd on win10 also resolves as expected

Reviewers: ngraham, meven

Reviewed By: ngraham, meven

Subscribers: kossebau, kde-frameworks-devel, kfm-devel

Tags: #dolphin, #frameworks

Differential Revision:
parent a2a8facc
......@@ -219,6 +219,36 @@ QUrl SMBSlave::checkURL(const QUrl &kurl_) const
// For WS-Discovered hosts we assume they'll respond to DNSSD names on .local but
// they may only respond to llmnr/netbios names. Transparently fall back.
// Desktop linuxes tend to have llmnr disabled, by contrast win10 has dnssd enabled,
// so chances are we'll be able to find a host.local more reliably.
// Attempt to resolve foo.local natively, if that works use it, otherwise default to
// the presumed LLMNR/netbios name found during discovery.
// This should then yield reasonable results with any combination of WSD/DNSSD/LLMNR support.
// - WSD+Avahi (on linux)
// - WSD+Win10 (i.e. dnssd + llmnr)
// - WSD+CrappyNAS (e.g. llmnr or netbios only)
// NB: smbc has no way to resolve a name without also triggering auth etc.: we must
// rely on the system's ability to resolve DNSSD for this check.
const QLatin1String wsdSuffix(".kio-discovery-wsd");
if ( {
QString host =;
const QString dnssd(host + ".local");
auto dnssdHost = QHostInfo::fromName(dnssd);
if (dnssdHost.error() == QHostInfo::NoError) {
qCDebug(KIO_SMB_LOG) << "Resolved DNSSD name:" << dnssd;
host = dnssd;
} else {
qCDebug(KIO_SMB_LOG) << "Failed to resolve DNSSD name:" << dnssd;
qCDebug(KIO_SMB_LOG) << "Falling back to LLMNR name:" << host;
QString surl = kurl.url();
// transform any links in the form smb:/ into smb://
if (surl.startsWith(QLatin1String("smb:/"))) {
......@@ -164,13 +164,20 @@ public:
// Default the host to the IP unless we have a prettyName in which case we use
// the presumed DNSSD name prettyName.local. listDir will redirect this to the
// LLMNR variant (without .local) should it turn out not resolvable.
QString host =;
if (computer.isEmpty()) {
computer = xi18nc("host entry when no pretty name is available. %1 likely is an IP address",
"Unknown Device @ <resource>%1</resource>",;
} else {
// If we got a DNSSD name, use that, otherwise redirect to on-demand resolution.
host = computer.endsWith(".local") ? computer : computer + ".kio-discovery-wsd";
m_discovery.reset(new WSDiscovery(computer,;
m_discovery.reset(new WSDiscovery(computer, host));
emit resolved(m_discovery);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment