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

@ -211,7 +211,9 @@ struct userdata {
#if defined(USE_TCP_SOCKETS)
pa_socket_server *socket_server_ipv4;
# ifdef HAVE_IPV6
pa_socket_server *socket_server_ipv6;
# endif
#else
pa_socket_server *socket_server_unix;
char *socket_path;
@ -299,20 +301,30 @@ int pa__init(pa_module*m) {
listen_on = pa_modargs_get_value(ma, "listen", NULL);
if (listen_on) {
# ifdef HAVE_IPV6
u->socket_server_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, (uint16_t) port, TCPWRAP_SERVICE);
# endif
u->socket_server_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, (uint16_t) port, TCPWRAP_SERVICE);
} else {
# ifdef HAVE_IPV6
u->socket_server_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, (uint16_t) port, TCPWRAP_SERVICE);
# endif
u->socket_server_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, (uint16_t) port, TCPWRAP_SERVICE);
}
# ifdef HAVE_IPV6
if (!u->socket_server_ipv4 && !u->socket_server_ipv6)
# else
if (!u->socket_server_ipv4)
# endif
goto fail;
if (u->socket_server_ipv4)
pa_socket_server_set_callback(u->socket_server_ipv4, socket_server_on_connection_cb, u);
# ifdef HAVE_IPV6
if (u->socket_server_ipv6)
pa_socket_server_set_callback(u->socket_server_ipv6, socket_server_on_connection_cb, u);
# endif
#else
@ -358,9 +370,11 @@ int pa__init(pa_module*m) {
if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
pa_native_protocol_add_server_string(u->native_protocol, t);
# ifdef HAVE_IPV6
if (u->socket_server_ipv6)
if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
pa_native_protocol_add_server_string(u->native_protocol, t);
# endif
# else
if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
pa_native_protocol_add_server_string(u->native_protocol, t);
@ -418,9 +432,11 @@ void pa__done(pa_module*m) {
if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
pa_native_protocol_remove_server_string(u->native_protocol, t);
# ifdef HAVE_IPV6
if (u->socket_server_ipv6)
if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
pa_native_protocol_remove_server_string(u->native_protocol, t);
# endif
# else
if (u->socket_server_unix)
if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
@ -444,8 +460,10 @@ void pa__done(pa_module*m) {
#if defined(USE_TCP_SOCKETS)
if (u->socket_server_ipv4)
pa_socket_server_unref(u->socket_server_ipv4);
# ifdef HAVE_IPV6
if (u->socket_server_ipv6)
pa_socket_server_unref(u->socket_server_ipv6);
# endif
#else
if (u->socket_server_unix)
pa_socket_server_unref(u->socket_server_unix);

View file

@ -373,11 +373,13 @@ static int mcast_socket(const struct sockaddr* sa, socklen_t salen) {
memset(&mr4, 0, sizeof(mr4));
mr4.imr_multiaddr = ((const struct sockaddr_in*) sa)->sin_addr;
r = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mr4, sizeof(mr4));
#ifdef HAVE_IPV6
} else {
struct ipv6_mreq mr6;
memset(&mr6, 0, sizeof(mr6));
mr6.ipv6mr_multiaddr = ((const struct sockaddr_in6*) sa)->sin6_addr;
r = setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mr6, sizeof(mr6));
#endif
}
if (r < 0) {
@ -608,7 +610,9 @@ int pa__init(pa_module*m) {
struct userdata *u;
pa_modargs *ma = NULL;
struct sockaddr_in sa4;
#ifdef HAVE_IPV6
struct sockaddr_in6 sa6;
#endif
struct sockaddr *sa;
socklen_t salen;
const char *sap_address;
@ -624,16 +628,18 @@ int pa__init(pa_module*m) {
sap_address = pa_modargs_get_value(ma, "sap_address", DEFAULT_SAP_ADDRESS);
if (inet_pton(AF_INET6, sap_address, &sa6.sin6_addr) > 0) {
sa6.sin6_family = AF_INET6;
sa6.sin6_port = htons(SAP_PORT);
sa = (struct sockaddr*) &sa6;
salen = sizeof(sa6);
} else if (inet_pton(AF_INET, sap_address, &sa4.sin_addr) > 0) {
if (inet_pton(AF_INET, sap_address, &sa4.sin_addr) > 0) {
sa4.sin_family = AF_INET;
sa4.sin_port = htons(SAP_PORT);
sa = (struct sockaddr*) &sa4;
salen = sizeof(sa4);
#ifdef HAVE_IPV6
} else if (inet_pton(AF_INET6, sap_address, &sa6.sin6_addr) > 0) {
sa6.sin6_family = AF_INET6;
sa6.sin6_port = htons(SAP_PORT);
sa = (struct sockaddr*) &sa6;
salen = sizeof(sa6);
#endif
} else {
pa_log("Invalid SAP address '%s'", sap_address);
goto fail;

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);

View file

@ -87,18 +87,31 @@ int pa_sap_send(pa_sap_context *c, pa_bool_t goodbye) {
return -1;
}
#ifdef HAVE_IPV6
pa_assert(sa->sa_family == AF_INET || sa->sa_family == AF_INET6);
#else
pa_assert(sa->sa_family == AF_INET);
#endif
header = htonl(((uint32_t) 1 << 29) |
#ifdef HAVE_IPV6
(sa->sa_family == AF_INET6 ? (uint32_t) 1 << 28 : 0) |
#endif
(goodbye ? (uint32_t) 1 << 26 : 0) |
(c->msg_id_hash));
iov[0].iov_base = &header;
iov[0].iov_len = sizeof(header);
iov[1].iov_base = sa->sa_family == AF_INET ? (void*) &((struct sockaddr_in*) sa)->sin_addr : (void*) &((struct sockaddr_in6*) sa)->sin6_addr;
iov[1].iov_len = sa->sa_family == AF_INET ? 4U : 16U;
if (sa->sa_family == AF_INET) {
iov[1].iov_base = (void*) &((struct sockaddr_in*) sa)->sin_addr;
iov[1].iov_len = 4U;
#ifdef HAVE_IPV6
} else {
iov[1].iov_base = (void*) &((struct sockaddr_in6*) sa)->sin6_addr;
iov[1].iov_len = 16U;
#endif
}
iov[2].iov_base = (char*) MIME_TYPE;
iov[2].iov_len = sizeof(MIME_TYPE);

View file

@ -48,7 +48,12 @@ char *pa_sdp_build(int af, const void *src, const void *dst, const char *name, u
pa_assert(src);
pa_assert(dst);
#ifdef HAVE_IPV6
pa_assert(af == AF_INET || af == AF_INET6);
#else
pa_assert(af == AF_INET);
#endif
pa_assert_se(f = pa_rtp_format_to_string(ss->format));
@ -162,6 +167,7 @@ pa_sdp_info *pa_sdp_parse(const char *t, pa_sdp_info *i, int is_goodbye) {
((struct sockaddr_in*) &i->sa)->sin_family = AF_INET;
((struct sockaddr_in*) &i->sa)->sin_port = 0;
i->salen = sizeof(struct sockaddr_in);
#ifdef HAVE_IPV6
} else if (pa_startswith(t, "c=IN IP6 ")) {
char a[64];
size_t k;
@ -179,6 +185,7 @@ pa_sdp_info *pa_sdp_parse(const char *t, pa_sdp_info *i, int is_goodbye) {
((struct sockaddr_in6*) &i->sa)->sin6_family = AF_INET6;
((struct sockaddr_in6*) &i->sa)->sin6_port = 0;
i->salen = sizeof(struct sockaddr_in6);
#endif
} else if (pa_startswith(t, "m=audio ")) {
if (i->payload > 127) {