summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlistair Leslie-Hughes <leslie_alistair@hotmail.com>2023-01-26 08:37:20 +1100
committerIgor Kovalenko <igor.v.kovalenko@gmail.com>2023-02-08 20:50:48 +0000
commit5cefef591ef6c0fd1c514202b0fcfbe466cab873 (patch)
tree7b2e0140030f19114bba9c5e52a820cb770c1e77
parentf44cb36374a6b72e33b03b555771137042aaf6b2 (diff)
downloadpulseaudio-5cefef591ef6c0fd1c514202b0fcfbe466cab873.tar.gz
rtp-recv: Use getaddrinfo to improve support for ipv6.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/774>
-rw-r--r--src/modules/rtp/module-rtp-recv.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index a67a993d1..9babf00cb 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -29,6 +29,9 @@
#include <string.h>
#include <unistd.h>
#include <math.h>
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
#include <pulse/rtclock.h>
#include <pulse/timeval.h>
@@ -677,10 +680,14 @@ static void check_death_event_cb(pa_mainloop_api *m, pa_time_event *t, const str
int pa__init(pa_module*m) {
struct userdata *u;
pa_modargs *ma = NULL;
+#if defined(HAVE_GETADDRINFO)
+ struct addrinfo *sap_addrinfo = NULL;
+#else
struct sockaddr_in sa4;
#ifdef HAVE_IPV6
struct sockaddr_in6 sa6;
#endif
+#endif
struct sockaddr *sa;
socklen_t salen;
const char *sap_address;
@@ -696,6 +703,27 @@ int pa__init(pa_module*m) {
sap_address = pa_modargs_get_value(ma, "sap_address", DEFAULT_SAP_ADDRESS);
+#if defined(HAVE_GETADDRINFO)
+ {
+ struct addrinfo hints;
+ char *service;
+
+ pa_zero(hints);
+
+ service = pa_sprintf_malloc("%d", htons(SAP_PORT));
+
+ hints.ai_flags = AI_NUMERICHOST;
+ if (getaddrinfo(sap_address, service, &hints, &sap_addrinfo) != 0) {
+ pa_xfree(service);
+ pa_log("Invalid SAP address '%s'", sap_address);
+ goto fail;
+ }
+ pa_xfree(service);
+
+ sa = sap_addrinfo->ai_addr;
+ salen = sap_addrinfo->ai_addrlen;
+ }
+#else
if (inet_pton(AF_INET, sap_address, &sa4.sin_addr) > 0) {
sa4.sin_family = AF_INET;
sa4.sin_port = htons(SAP_PORT);
@@ -712,6 +740,7 @@ int pa__init(pa_module*m) {
pa_log("Invalid SAP address '%s'", sap_address);
goto fail;
}
+#endif
latency_msec = DEFAULT_LATENCY_MSEC;
if (pa_modargs_get_value_u32(ma, "latency_msec", &latency_msec) < 0 || latency_msec < 1 || latency_msec > 300000) {
@@ -739,9 +768,18 @@ int pa__init(pa_module*m) {
pa_modargs_free(ma);
+#if defined(HAVE_GETADDRINFO)
+ freeaddrinfo(sap_addrinfo);
+#endif
+
return 0;
fail:
+#if defined(HAVE_GETADDRINFO)
+ if (sap_addrinfo)
+ freeaddrinfo(sap_addrinfo);
+#endif
+
if (ma)
pa_modargs_free(ma);