From 19045db39296dfb2ed2dc42814b0199f0bc45b54 Mon Sep 17 00:00:00 2001
From: George Joseph <gjoseph@digium.com>
Date: Wed, 21 Aug 2019 12:29:57 -0600
Subject: [PATCH] chan_rtp:  Accept hostname as well as ip address as
 destination

The UnicastRTP channel driver provided by chan_rtp now accepts
"<hostname>:<port>" as an alternative to "<ip_address>:<port>"
in the destination. The first AAAA (preferred) or A record resolved
will be used as the destination. The lookup is synchronous so beware
of possible dialplan delays if you specify a hostname.

Change-Id: Ie6f95b983a8792bf0dacc64c7953a41032dba677
---
 channels/chan_rtp.c              | 19 +++++++++++++++++--
 doc/CHANGES-staging/chan_rtp.txt |  7 +++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 doc/CHANGES-staging/chan_rtp.txt

diff --git a/channels/chan_rtp.c b/channels/chan_rtp.c
index 7d9e26db89..d8f7324c84 100644
--- a/channels/chan_rtp.c
+++ b/channels/chan_rtp.c
@@ -43,6 +43,7 @@
 #include "asterisk/causes.h"
 #include "asterisk/format_cache.h"
 #include "asterisk/multicast_rtp.h"
+#include "asterisk/dns_core.h"
 
 /* Forward declarations */
 static struct ast_channel *multicast_rtp_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause);
@@ -293,9 +294,23 @@ static struct ast_channel *unicast_rtp_request(const char *type, struct ast_form
 		ast_log(LOG_ERROR, "Destination is required for the 'UnicastRTP' channel\n");
 		goto failure;
 	}
+
 	if (!ast_sockaddr_parse(&address, args.destination, PARSE_PORT_REQUIRE)) {
-		ast_log(LOG_ERROR, "Destination '%s' could not be parsed\n", args.destination);
-		goto failure;
+	    int rc;
+	    char *host;
+	    char *port;
+
+	    rc = ast_sockaddr_split_hostport(args.destination, &host, &port, PARSE_PORT_REQUIRE);
+	    if (!rc) {
+	        ast_log(LOG_ERROR, "Unable to parse destination '%s' into host and port\n", args.destination);
+	        goto failure;
+	    }
+
+	    rc = ast_dns_resolve_ipv6_and_ipv4(&address, host, port);
+	    if (rc != 0) {
+	        ast_log(LOG_ERROR, "Unable to resolve host '%s'\n", host);
+	        goto failure;
+	    }
 	}
 
 	if (!ast_strlen_zero(args.options)
diff --git a/doc/CHANGES-staging/chan_rtp.txt b/doc/CHANGES-staging/chan_rtp.txt
new file mode 100644
index 0000000000..ce908ee037
--- /dev/null
+++ b/doc/CHANGES-staging/chan_rtp.txt
@@ -0,0 +1,7 @@
+Subject: chan_rtp
+
+The UnicastRTP channel driver provided by chan_rtp now accepts
+"<hostname>:<port>" as an alternative to "<ip_address>:<port>" in the destination.
+The first AAAA (preferred) or A record resolved will be used as the destination.
+The lookup is synchronous so beware of possible dialplan delays if you specify a
+hostname.
-- 
GitLab