[vlc-devel] [PATCH 4/4] smb2: print the connected address

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Nov 12 16:03:16 CET 2020


Hi,

On Thu, Nov 12, 2020, at 3:29 PM, Thomas Guillem wrote:
> ---
>  modules/access/smb2.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/modules/access/smb2.c b/modules/access/smb2.c
> index d45a573e8a..9168b6987b 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)

Are you sure no getsockname implementation will ever try to write to that value?

> +        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)

Can't you pass 'addr' as a 'struct sockaddr*' directly here and avoid the above switch?

> +        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.28.0
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel

-- 
  Hugo Beauzée-Luyssen
  hugo at beauzee.fr


More information about the vlc-devel mailing list