Exemple #1
0
int main(int ac, char **av)
{
  netbios_ns        *ns;
  struct in_addr      addr;
  const char          *name;

  ns = netbios_ns_new();

  if (ac != 2)
  {
    fprintf(stderr, "%s usage: %s a.b.c.d\n", av[0], av[0]);
    fprintf(stderr, "Print the netbios name for this IP address\n");
    exit(1);
  }

  inet_aton(av[1], &addr);
  if ((name = netbios_ns_inverse(ns, addr.s_addr)) == NULL)
  {
    fprintf(stderr, "Unable to perform inverse name resolution for %s\n", av[1]);
    exit(42);
  }

  printf("%s\n", name);
  netbios_ns_destroy(ns);
  return (0);
}
Exemple #2
0
/* Returns VLC_EGENERIC if it wasn't able to get an ip address to connect to */
static int get_address( stream_t *p_access )
{
    access_sys_t *p_sys = p_access->p_sys;

    if( p_sys->url.psz_host != NULL &&
        !inet_pton( AF_INET, p_sys->url.psz_host, &p_sys->addr ) )
    {
        /* This is not an ip address, let's try netbios/dns resolve */
        struct addrinfo *p_info = NULL;

        /* Is this a netbios name on this LAN ? */
        if( netbios_ns_resolve( p_sys->p_ns, p_sys->url.psz_host,
                                NETBIOS_FILESERVER,
                                &p_sys->addr.s_addr) == 0 )
        {
            strlcpy( p_sys->netbios_name, p_sys->url.psz_host, 16);
            return VLC_SUCCESS;
        }
        /* or is it an existing dns name ? */
        else if( getaddrinfo( p_sys->url.psz_host, NULL, NULL, &p_info ) == 0 )
        {
            if( p_info->ai_family == AF_INET )
            {
                struct sockaddr_in *in = (struct sockaddr_in *)p_info->ai_addr;
                p_sys->addr.s_addr = in->sin_addr.s_addr;
            }
            if( p_info->ai_family != AF_INET )
            {
                freeaddrinfo( p_info );
                return VLC_EGENERIC;
            }
            freeaddrinfo( p_info );
        }
        else
            return VLC_EGENERIC;
    }

    /* We have an IP address, let's find the NETBIOS name */
    const char *psz_nbt = netbios_ns_inverse( p_sys->p_ns, p_sys->addr.s_addr );
    if( psz_nbt != NULL )
        strlcpy( p_sys->netbios_name, psz_nbt, 16 );
    else
    {
        msg_Warn( p_access, "Unable to get netbios name of %s",
            p_sys->url.psz_host );
        p_sys->netbios_name[0] = '\0';
    }

    return VLC_SUCCESS;
}