[vlc-commits] microdns: fix ipv6 support
Thomas Guillem
git at videolan.org
Fri May 27 15:49:59 CEST 2016
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri May 27 15:48:44 2016 +0200| [9503a2c7de45968703e9f3c0ba68bc3a65fccd82] | committer: Thomas Guillem
microdns: fix ipv6 support
psz_ip6 was invalid outside parse_entries()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9503a2c7de45968703e9f3c0ba68bc3a65fccd82
---
modules/services_discovery/microdns.c | 37 ++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/modules/services_discovery/microdns.c b/modules/services_discovery/microdns.c
index 247fb19..f7e5fe8 100644
--- a/modules/services_discovery/microdns.c
+++ b/modules/services_discovery/microdns.c
@@ -282,7 +282,7 @@ items_clear( struct discovery_sys *p_sys )
static int
parse_entries( const struct rr_entry *p_entries, bool b_renderer,
struct srv **pp_srvs, unsigned int *p_nb_srv,
- const char **ppsz_ip )
+ const char **ppsz_ip, bool *p_ipv6 )
{
/* Count the number of servers */
unsigned int i_nb_srv = 0;
@@ -301,7 +301,6 @@ parse_entries( const struct rr_entry *p_entries, bool b_renderer,
/* There is one ip for several srvs, fetch them */
const char *psz_ip = NULL;
- char psz_ip6[INET6_ADDRSTRLEN + 2];
i_nb_srv = 0;
for( const struct rr_entry *p_entry = p_entries;
p_entry != NULL; p_entry = p_entry->next )
@@ -332,8 +331,8 @@ parse_entries( const struct rr_entry *p_entries, bool b_renderer,
psz_ip = p_entry->data.A.addr_str;
else if( p_entry->type == RR_AAAA && psz_ip == NULL )
{
- if (snprintf(psz_ip6, sizeof(psz_ip6), "[%s]", p_entry->data.AAAA.addr_str) > 0)
- psz_ip = psz_ip6;
+ psz_ip = p_entry->data.AAAA.addr_str;
+ *p_ipv6 = true;
}
}
if( psz_ip == NULL || i_nb_srv == 0 )
@@ -348,6 +347,17 @@ parse_entries( const struct rr_entry *p_entries, bool b_renderer,
return VLC_SUCCESS;
}
+static char *
+create_uri( const char *psz_protocol, const char *psz_ip, bool b_ipv6,
+ uint16_t i_port )
+{
+ char *psz_uri;
+
+ return asprintf( &psz_uri, "%s://%s%s%s:%u", psz_protocol,
+ b_ipv6 ? "[" : "", psz_ip, b_ipv6 ? "]" : "",
+ i_port ) < 0 ? NULL : psz_uri;
+}
+
static void
new_entries_sd_cb( void *p_this, int i_status, const struct rr_entry *p_entries )
{
@@ -362,18 +372,19 @@ new_entries_sd_cb( void *p_this, int i_status, const struct rr_entry *p_entries
struct srv *p_srvs;
unsigned i_nb_srv;
const char *psz_ip;
+ bool b_ipv6;
if( parse_entries( p_entries, false, &p_srvs, &i_nb_srv,
- &psz_ip ) != VLC_SUCCESS )
+ &psz_ip, &b_ipv6 ) != VLC_SUCCESS )
return;
/* send new input items (if they don't already exist) */
for( unsigned int i = 0; i < i_nb_srv; ++i )
{
struct srv *p_srv = &p_srvs[i];
- char *psz_uri;
+ char *psz_uri = create_uri( p_srv->psz_protocol, psz_ip, b_ipv6,
+ p_srv->i_port );
- if( asprintf( &psz_uri, "%s://%s:%u", p_srv->psz_protocol, psz_ip,
- p_srv->i_port ) < 0 )
+ if( psz_uri == NULL )
break;
if( items_exists( p_sys, psz_uri ) )
@@ -437,8 +448,9 @@ new_entries_rd_cb( void *p_this, int i_status, const struct rr_entry *p_entries
struct srv *p_srvs;
unsigned i_nb_srv;
const char *psz_ip;
+ bool b_ipv6;
if( parse_entries( p_entries, true, &p_srvs, &i_nb_srv,
- &psz_ip ) != VLC_SUCCESS )
+ &psz_ip, &b_ipv6 ) != VLC_SUCCESS )
return;
const char *psz_model = NULL;
@@ -468,10 +480,11 @@ new_entries_rd_cb( void *p_this, int i_status, const struct rr_entry *p_entries
for( unsigned int i = 0; i < i_nb_srv; ++i )
{
struct srv *p_srv = &p_srvs[i];
- char *psz_uri, *psz_icon_uri = NULL;
+ char *psz_icon_uri = NULL;
+ char *psz_uri = create_uri( p_srv->psz_protocol, psz_ip, b_ipv6,
+ p_srv->i_port );
- if( asprintf( &psz_uri, "%s://%s:%u", p_srv->psz_protocol, psz_ip,
- p_srv->i_port ) == -1 )
+ if( psz_uri == NULL )
break;
if( items_exists( p_sys, psz_uri ) )
More information about the vlc-commits
mailing list