[vlc-devel] [PATCH 6/6] smb2: print connected ipaddr
Thomas Guillem
thomas at gllm.fr
Tue Mar 2 14:52:25 UTC 2021
---
modules/access/smb2.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index 384d393479e..885e1c74a32 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_Warn(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);
--
2.30.0
More information about the vlc-devel
mailing list