hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
713 stars 180 forks source link

netbios/samba host resolution #586

Open mvysny opened 3 years ago

mvysny commented 3 years ago

Hello, thank you so much for your excellent library.

Unfortunately the samba-proprietary/netbios name resolving doesn't seem to be supported by SMBJ.

In my network I use mdns which is supported by Linux but doesn't seem to be supported by Android. A couple of commands and their output:

nmblookup mycloud
192.168.0.22 mycloud<00>

host mycloud
Host mycloud not found: 2(SERVFAIL)

host mycloud.local
Host mycloud.local not found: 3(NXDOMAIN)

ping mycloud.local
PING mycloud.local (192.168.0.22) 56(84) bytes of data.
64 bytes from 192.168.0.22 (192.168.0.22): icmp_seq=1 ttl=64 time=0.551 ms

avahi-resolve --name mycloud.local
mycloud.local   192.168.0.22

You can see that the router itself doesn't provide any DNS services and therefore mycloud nor mycloud.local is not resolvable via direct DNS query; however ping mycloud.local works since it resolves the name via mdns; browsing the samba server mycloud also works since samba client resolves the mycloud host name via Samba host lookup.

However, SMBJ doesn't seem to be supporting the lookup and will simply fail with:

E/PhotoFrame:AddSamba3Sh*: Failed to connect to the Samba server mycloud/public
    java.net.UnknownHostException: klada.local
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:208)
        at java.net.Socket.connect(Socket.java:621)
        at com.hierynomus.protocol.commons.socket.ProxySocketFactory.createSocket(ProxySocketFactory.java:87)
        at com.hierynomus.protocol.commons.socket.ProxySocketFactory.createSocket(ProxySocketFactory.java:63)
        at com.hierynomus.smbj.transport.tcp.direct.DirectTcpTransport.connect(DirectTcpTransport.java:88)
        at com.hierynomus.smbj.connection.Connection.connect(Connection.java:119)
        at com.hierynomus.smbj.SMBClient.getEstablishedOrConnect(SMBClient.java:106)
        at com.hierynomus.smbj.SMBClient.connect(SMBClient.java:77)
        at ch.swaechter.smbjwrapper.SmbConnection.<init>(SmbConnection.java:61)
        at sk.baka.photoframe.fsimpl.samba3.Samba3FileSystem.connect(Samba3FileSystem.kt:51)
mvysny commented 3 years ago

Calling .withDfsEnabled(true) unfortunately did not help.

zhanghai commented 3 years ago

Hi mvysny, I'm running into the same issue as the developer of zhanghai/MaterialFiles when adding SMB support. I saw you've resolved this issue in mvysny/photocloud-frame-slideshow#141, so I was wondering if you could share with me what was your solution to this? Currently I'm thinking of using codelibs/jcifs to resolve the NetBIOS hostname before sending it to SMBJ, but not sure if this would be a good solution.

mvysny commented 3 years ago

@zhanghai unfortunately I haven't solved this yet - the users must enter an IP address in order to connect. The jcifs solution looks like a great suggestion though! However I wonder whether there are any netbios java client libraries... :thinking: quick google for 'java netbios' shows that everyone seems to be using jcifs.

zhanghai commented 3 years ago

I see, thanks anyway! I'll explore using jcifs for name resolution.