diff options
author | Alistair Leslie-Hughes <leslie_alistair@hotmail.com> | 2023-01-02 21:05:15 +1100 |
---|---|---|
committer | PulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org> | 2023-01-21 10:10:02 +0000 |
commit | f8b90105824ac66a30e56efb32a44dc896f2b2c5 (patch) | |
tree | 88e7c353191398264e9cdde16c677844e0f15979 /src/modules/rtp/module-rtp-send.c | |
parent | 6473e9ed0e3fc3c9be4d6d3df93183f44a0dcb85 (diff) | |
download | pulseaudio-f8b90105824ac66a30e56efb32a44dc896f2b2c5.tar.gz |
rtp-send: Use getaddrinfo to improve support for ipv6.
inet_pton isn't guarantee to support IPV6 address when a scope has been specified.
Using getaddrinfo instead, we can safely pass through INET6+scope and have it translated
to a usable address.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/766>
Diffstat (limited to 'src/modules/rtp/module-rtp-send.c')
-rw-r--r-- | src/modules/rtp/module-rtp-send.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index fd5b63abe..e917105c7 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -26,6 +26,9 @@ #include <netinet/in.h> #include <errno.h> #include <unistd.h> +#ifdef HAVE_NETDB_H +#include <netdb.h> +#endif #include <pulse/rtclock.h> #include <pulse/timeval.h> @@ -338,6 +341,44 @@ int pa__init(pa_module*m) { if (dst_addr == NULL) dst_addr = pa_modargs_get_value(ma, "destination_ip", DEFAULT_DESTINATION_IP); +#if defined(HAVE_GETADDRINFO) + { + struct addrinfo *dst_addrinfo = NULL; + struct addrinfo hints; + + pa_zero(hints); + + hints.ai_flags = AI_NUMERICHOST; + if (getaddrinfo(dst_addr, NULL, &hints, &dst_addrinfo) != 0) { + pa_log("Invalid destination '%s'", dst_addr); + goto fail; + } + + af = dst_addrinfo->ai_family; + if (af == AF_INET) { + memcpy(&dst_sa4, dst_addrinfo->ai_addr, dst_addrinfo->ai_addrlen); + dst_sa4.sin_port = htons((uint16_t) port); + dst_sap_sa4 = dst_sa4; + dst_sap_sa4.sin_port = htons(SAP_PORT); + } +#ifdef HAVE_IPV6 + else if (af == AF_INET6) { + memcpy(&dst_sa6, dst_addrinfo->ai_addr, dst_addrinfo->ai_addrlen); + dst_sa6.sin6_port = htons((uint16_t) port); + dst_sap_sa6 = dst_sa6; + dst_sap_sa6.sin6_port = htons(SAP_PORT); + } +#endif + else + { + freeaddrinfo(dst_addrinfo); + pa_log("Invalid destination '%s'", dst_addr); + goto fail; + } + + freeaddrinfo(dst_addrinfo); + } +#else if (inet_pton(AF_INET, dst_addr, &dst_sa4.sin_addr) > 0) { dst_sa4.sin_family = af = AF_INET; dst_sa4.sin_port = htons((uint16_t) port); @@ -357,6 +398,7 @@ int pa__init(pa_module*m) { pa_log("Invalid destination '%s'", dst_addr); goto fail; } +#endif /* HAVE_GETADDRINFO */ if ((fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) { pa_log("socket() failed: %s", pa_cstrerror(errno)); |