[vlc-commits] smb2: add libdsm netbios resolver

Thomas Guillem git at videolan.org
Sat Jul 7 22:01:11 CEST 2018


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Apr 19 14:37:44 2018 +0200| [5775166f1bc6021fed15ab8fef7e0f7a014292a5] | committer: Thomas Guillem

smb2: add libdsm netbios resolver

Because libsmb2 doesn't have any netbios name resolver.

Maybe, every VLC services discoveries should use the IP instead of the netbios
name for SMB shares.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5775166f1bc6021fed15ab8fef7e0f7a014292a5
---

 configure.ac               |  9 ++++++++-
 modules/access/Makefile.am |  4 ++++
 modules/access/smb2.c      | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index b5b052f030..41f08aff8c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1841,7 +1841,14 @@ PKG_ENABLE_MODULES_VLC([SMBCLIENT], [smbc], [smbclient], (SMB/CIFS support), [au
 dnl
 dnl  liBDSM access module
 dnl
-PKG_ENABLE_MODULES_VLC([DSM], [dsm], [libdsm >= 0.2.0], [libdsm SMB/CIFS access/sd module], [auto])
+AM_CONDITIONAL(HAVE_DSM, [test "$AS_TR_SH(with_dsm)" = "yes"])
+PKG_WITH_MODULES([DSM], [libdsm >= 0.2.0], [
+       VLC_ADD_PLUGIN([dsm])
+       VLC_ADD_CFLAGS([dsm], [$DSM_CFLAGS])
+       VLC_ADD_LIBS([dsm], [$DSM_LIBS])
+       have_dsm="yes"
+   ],,[libdsm SMB/CIFS access/sd module], [auto])
+AM_CONDITIONAL([HAVE_DSM], [test "${have_dsm}" = "yes"])
 
 dnl
 dnl sftp access support
diff --git a/modules/access/Makefile.am b/modules/access/Makefile.am
index 9cd9b01197..ae39f59a4d 100644
--- a/modules/access/Makefile.am
+++ b/modules/access/Makefile.am
@@ -357,6 +357,10 @@ libsmb2_plugin_la_SOURCES = access/smb2.c
 libsmb2_plugin_la_CFLAGS = $(AM_CFLAGS) $(SMB2_CFLAGS)
 libsmb2_plugin_la_LIBADD = $(SMB2_LIBS) $(SOCKET_LIBS)
 libsmb2_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(accessdir)'
+if HAVE_DSM
+libsmb2_plugin_la_CFLAGS += $(DSM_CFLAGS) -DHAVE_DSM
+libsmb2_plugin_la_LIBADD += $(DSM_LIBS)
+endif
 access_LTLIBRARIES += $(LTLIBsmb2)
 EXTRA_LTLIBRARIES += libsmb2_plugin.la
 
diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index 3db718bc33..9bd5a1fea8 100644
--- a/modules/access/smb2.c
+++ b/modules/access/smb2.c
@@ -47,6 +47,15 @@
 #include <smb2/libsmb2.h>
 #include <smb2/libsmb2-raw.h>
 
+#ifdef HAVE_DSM
+# include <bdsm/netbios_ns.h>
+# include <bdsm/netbios_defs.h>
+
+# ifdef HAVE_ARPA_INET_H
+#  include <arpa/inet.h>
+# endif
+#endif
+
 #include "smb_common.h"
 
 #define CIFS_PORT 445
@@ -527,12 +536,46 @@ error:
 static int
 vlc_smb2_resolve(stream_t *access, char **host, unsigned port)
 {
+    (void) access;
     if (!*host)
         return -1;
 
-    (void) access;
+#ifdef HAVE_DSM
+    /* Test if the host is an IP */
+    struct in_addr addr;
+    if (inet_pton(AF_INET, *host, &addr) == 1)
+        return 0;
+
+    /* Test if the host can be resolved */
+    struct addrinfo *info = NULL;
+    if (vlc_getaddrinfo_i11e(*host, port, NULL, &info) == 0)
+    {
+        freeaddrinfo(info);
+        /* Let smb2 resolve it */
+        return 0;
+    }
+
+    /* Test if the host is a netbios name */
+    netbios_ns *ns = netbios_ns_new();
+    uint32_t ip4_addr;
+    int ret = -1;
+    if (netbios_ns_resolve(ns, *host, NETBIOS_FILESERVER, &ip4_addr) == 0)
+    {
+        char ip[] = "xxx.xxx.xxx.xxx";
+        if (inet_ntop(AF_INET, &ip4_addr, ip, sizeof(ip)))
+        {
+            free(*host);
+            *host = strdup(ip);
+            if (*host)
+                ret = 0;
+        }
+    }
+    netbios_ns_destroy(ns);
+    return ret;
+#else
     (void) port;
     return 0;
+#endif
 }
 
 static int



More information about the vlc-commits mailing list