[vlc-commits] smb2: print connected ipaddr

Thomas Guillem git at videolan.org
Fri Mar 12 09:40:37 UTC 2021


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Mar  2 15:44:49 2021 +0100| [63329029a150f412b7a10b1ebd1fd40cdad847c0] | committer: Thomas Guillem

smb2: print connected ipaddr

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

 modules/access/smb2.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index 384d393479..069bc74e41 100644
--- a/modules/access/smb2.c
+++ b/modules/access/smb2.c
@@ -520,6 +520,38 @@ smb2_share_enum_cb(struct smb2_context *smb2, int status, void *data,
     sys->share_enum = data;
 }
 
+static void
+vlc_smb2_print_addr(stream_t *access)
+{
+    struct access_sys *sys = access->p_sys;
+
+    struct sockaddr_storage addr;
+    if (getsockname(smb2_get_fd(sys->smb2), (struct sockaddr *)&addr,
+                    &(socklen_t){ sizeof(addr) }) != 0)
+        return;
+
+    void *sin_addr;
+    switch (addr.ss_family)
+    {
+        case AF_INET6:
+            sin_addr = &((struct sockaddr_in6 *)&addr)->sin6_addr;
+            break;
+        case AF_INET:
+            sin_addr = &((struct sockaddr_in *)&addr)->sin_addr;
+            break;
+        default:
+            return;
+    }
+    char ip[INET6_ADDRSTRLEN];
+    if (inet_ntop(addr.ss_family, sin_addr, ip, sizeof(ip)) == NULL)
+        return;
+
+    if (strcmp(ip, sys->encoded_url.psz_host) == 0)
+        return;
+
+    msg_Dbg(access, "%s: connected from %s\n", sys->encoded_url.psz_host, ip);
+}
+
 static int
 vlc_smb2_open_share(stream_t *access, const char *url,
                     const vlc_credential *credential)
@@ -569,6 +601,8 @@ vlc_smb2_open_share(stream_t *access, const char *url,
         goto error;
     sys->smb2_connected = true;
 
+    vlc_smb2_print_addr(access);
+
     int ret;
     if (do_enum)
         ret = smb2_share_enum_async(sys->smb2, smb2_share_enum_cb, access);



More information about the vlc-commits mailing list