Add IPv6 support to player and RAOP for device discovery

This commit is contained in:
Julien BLACHE 2010-05-14 17:37:55 +02:00
parent c9818e9269
commit b8238e6a78
3 changed files with 81 additions and 22 deletions

View File

@ -1046,7 +1046,12 @@ static void
device_free(struct raop_device *dev)
{
free(dev->name);
free(dev->address);
if (dev->v4_address)
free(dev->v4_address);
if (dev->v6_address)
free(dev->v6_address);
free(dev);
}
@ -2762,9 +2767,6 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
int has_password;
int ret;
if (family != AF_INET)
return;
ret = safe_hextou64(name, &id);
if (ret < 0)
{
@ -2807,6 +2809,27 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
return;
}
switch (family)
{
case AF_INET:
if (rd->v4_address)
{
free(rd->v4_address);
rd->v4_address = NULL;
}
break;
case AF_INET6:
if (rd->v6_address)
{
free(rd->v6_address);
rd->v6_address = NULL;
}
break;
}
if (!rd->v4_address && !rd->v6_address)
{
rd->advertised = 0;
if (!rd->session)
@ -2820,6 +2843,7 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
DPRINTF(E_DBG, L_PLAYER, "Removed AirTunes device %s; stopped advertising\n", name);
}
}
pthread_mutex_unlock(&dev_lck);
}
@ -2872,7 +2896,25 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
DPRINTF(E_DBG, L_PLAYER, "Updating AirTunes device %s already in list, updating\n", name);
free(rd->name);
free(rd->address);
switch (family)
{
case AF_INET:
if (rd->v4_address)
{
free(rd->v4_address);
rd->v4_address = NULL;
}
break;
case AF_INET6:
if (rd->v6_address)
{
free(rd->v6_address);
rd->v6_address = NULL;
}
break;
}
}
else
{
@ -2897,10 +2939,21 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
}
rd->advertised = 1;
rd->port = port;
switch (family)
{
case AF_INET:
rd->v4_address = strdup(address);
rd->v4_port = port;
break;
case AF_INET6:
rd->v6_address = strdup(address);
rd->v6_port = port;
break;
}
rd->name = strdup(at_name);
rd->address = strdup(address);
rd->has_password = has_password;
rd->password = val;

View File

@ -1341,6 +1341,9 @@ raop_session_make(struct raop_device *rd, raop_status_cb cb)
struct raop_session *rs;
int ret;
if (!rd->v4_address)
return NULL;
rs = (struct raop_session *)malloc(sizeof(struct raop_session));
if (!rs)
{
@ -1360,15 +1363,15 @@ raop_session_make(struct raop_device *rd, raop_status_cb cb)
rs->password = rd->password;
rs->sa.sin.sin_family = AF_INET;
ret = inet_pton(AF_INET, rd->address, &rs->sa.sin.sin_addr.s_addr);
ret = inet_pton(AF_INET, rd->v4_address, &rs->sa.sin.sin_addr.s_addr);
if (ret <= 0)
{
DPRINTF(E_LOG, L_RAOP, "Device address not valid (%s)\n", rd->address);
DPRINTF(E_LOG, L_RAOP, "Device address not valid (%s)\n", rd->v4_address);
goto out_free_rs;
}
rs->ctrl = evrtsp_connection_new(rd->address, rd->port);
rs->ctrl = evrtsp_connection_new(rd->v4_address, rd->v4_port);
if (!rs->ctrl)
{
DPRINTF(E_LOG, L_RAOP, "Could not create control connection\n");
@ -1379,7 +1382,7 @@ raop_session_make(struct raop_device *rd, raop_status_cb cb)
evrtsp_connection_set_base(rs->ctrl, evbase_player);
rs->devname = strdup(rd->name);
rs->address = strdup(rd->address);
rs->address = strdup(rd->v4_address);
rs->next = sessions;
sessions = rs;

View File

@ -11,6 +11,7 @@
union sockaddr_all
{
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
struct sockaddr sa;
struct sockaddr_storage ss;
};
@ -22,8 +23,10 @@ struct raop_device
uint64_t id;
char *name;
char *address;
short port;
char *v4_address;
char *v6_address;
short v4_port;
short v6_port;
char selected;
char advertised;