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

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



On Thu, Nov 12, 2020, at 4:14 PM, Thomas Guillem wrote:
> 
> 
> On Thu, Nov 12, 2020, at 16:03, Hugo Beauzée-Luyssen wrote:
> > 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?
> 
> I will use an intermediate variable. The returned size need to be checked.
> 
> > 
> > > +        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?
> 
> Naup, you can't, sin_addr and sin6_addr have different offsets.
> 

Ah yes my bad it takes a pointer to struct in(6)_addr, not to struct sockaddr.


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


More information about the vlc-devel mailing list