mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
rtp-recv: Use getaddrinfo to improve support for ipv6.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/774>
This commit is contained in:
parent
f44cb36374
commit
5cefef591e
1 changed files with 38 additions and 0 deletions
|
|
@ -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,9 +680,13 @@ 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;
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue