Optionally disable IPv6

Closes #79
This commit is contained in:
Iain Hibbert 2009-02-13 21:58:09 +01:00 committed by Lennart Poettering
parent 9334d900e5
commit dc590c7d0a
15 changed files with 179 additions and 23 deletions

View file

@ -177,7 +177,9 @@ int pa__init(pa_module*m) {
pa_sample_spec ss;
pa_channel_map cm;
struct sockaddr_in sa4, sap_sa4;
#ifdef HAVE_IPV6
struct sockaddr_in6 sa6, sap_sa6;
#endif
struct sockaddr_storage sa_dst;
pa_source_output *o = NULL;
uint8_t payload;
@ -247,16 +249,18 @@ int pa__init(pa_module*m) {
dest = pa_modargs_get_value(ma, "destination", DEFAULT_DESTINATION);
if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) {
sa6.sin6_family = af = AF_INET6;
sa6.sin6_port = htons((uint16_t) port);
sap_sa6 = sa6;
sap_sa6.sin6_port = htons(SAP_PORT);
} else if (inet_pton(AF_INET, dest, &sa4.sin_addr) > 0) {
if (inet_pton(AF_INET, dest, &sa4.sin_addr) > 0) {
sa4.sin_family = af = AF_INET;
sa4.sin_port = htons((uint16_t) port);
sap_sa4 = sa4;
sap_sa4.sin_port = htons(SAP_PORT);
#ifdef HAVE_IPV6
} else if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) {
sa6.sin6_family = af = AF_INET6;
sa6.sin6_port = htons((uint16_t) port);
sap_sa6 = sa6;
sap_sa6.sin6_port = htons(SAP_PORT);
#endif
} else {
pa_log("Invalid destination '%s'", dest);
goto fail;
@ -267,9 +271,14 @@ int pa__init(pa_module*m) {
goto fail;
}
if (connect(fd, af == AF_INET ? (struct sockaddr*) &sa4 : (struct sockaddr*) &sa6, (socklen_t) (af == AF_INET ? sizeof(sa4) : sizeof(sa6))) < 0) {
if (af == AF_INET && connect(fd, (struct sockaddr*) &sa4, sizeof(sa4)) < 0) {
pa_log("connect() failed: %s", pa_cstrerror(errno));
goto fail;
#ifdef HAVE_IPV6
} else if (af == AF_INET6 && connect(fd, (struct sockaddr*) &sa6, sizeof(sa6)) < 0) {
pa_log("connect() failed: %s", pa_cstrerror(errno));
goto fail;
#endif
}
if ((sap_fd = socket(af, SOCK_DGRAM, 0)) < 0) {
@ -277,9 +286,14 @@ int pa__init(pa_module*m) {
goto fail;
}
if (connect(sap_fd, af == AF_INET ? (struct sockaddr*) &sap_sa4 : (struct sockaddr*) &sap_sa6, (socklen_t) (af == AF_INET ? sizeof(sap_sa4) : sizeof(sap_sa6))) < 0) {
if (af == AF_INET && connect(sap_fd, (struct sockaddr*) &sap_sa4, sizeof(sap_sa4)) < 0) {
pa_log("connect() failed: %s", pa_cstrerror(errno));
goto fail;
#ifdef HAVE_IPV6
} else if (af == AF_INET6 && connect(sap_fd, (struct sockaddr*) &sap_sa6, sizeof(sap_sa6)) < 0) {
pa_log("connect() failed: %s", pa_cstrerror(errno));
goto fail;
#endif
}
j = !!loop;
@ -357,10 +371,19 @@ int pa__init(pa_module*m) {
n = pa_sprintf_malloc("PulseAudio RTP Stream on %s", pa_get_fqdn(hn, sizeof(hn)));
p = pa_sdp_build(af,
af == AF_INET ? (void*) &((struct sockaddr_in*) &sa_dst)->sin_addr : (void*) &((struct sockaddr_in6*) &sa_dst)->sin6_addr,
af == AF_INET ? (void*) &sa4.sin_addr : (void*) &sa6.sin6_addr,
if (af == AF_INET) {
p = pa_sdp_build(af,
(void*) &((struct sockaddr_in*) &sa_dst)->sin_addr,
(void*) &sa4.sin_addr,
n, (uint16_t) port, payload, &ss);
#ifdef HAVE_IPV6
} else {
p = pa_sdp_build(af,
(void*) &((struct sockaddr_in6*) &sa_dst)->sin6_addr,
(void*) &sa6.sin6_addr,
n, (uint16_t) port, payload, &ss);
#endif
}
pa_xfree(n);