[sr-dev] git:master:491d1261: rtpengine: remove square brackets from IPv6 address for getaddrinfo function

Daniel-Constantin Mierla miconda at gmail.com
Mon Mar 22 15:42:21 CET 2021


Module: kamailio
Branch: master
Commit: 491d1261e04e09f13990d5062c21faca7eb32b37
URL: https://github.com/kamailio/kamailio/commit/491d1261e04e09f13990d5062c21faca7eb32b37

Author: Dennis Yurasov <dennis-y at yandex-team.ru>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-03-22T15:42:16+01:00

rtpengine: remove square brackets from IPv6 address for getaddrinfo function

- After loading from DB rn_address is in form: [x:x:x:x:x:x:x:x]:nnnn, getaddrinfo function expect ipv6 in node argument without square brackets, otherwise, the argument is interpreted as FQDN.

---

Modified: src/modules/rtpengine/rtpengine.c

---

Diff:  https://github.com/kamailio/kamailio/commit/491d1261e04e09f13990d5062c21faca7eb32b37.diff
Patch: https://github.com/kamailio/kamailio/commit/491d1261e04e09f13990d5062c21faca7eb32b37.patch

---

diff --git a/src/modules/rtpengine/rtpengine.c b/src/modules/rtpengine/rtpengine.c
index 8b751eb48a..7114b08d40 100644
--- a/src/modules/rtpengine/rtpengine.c
+++ b/src/modules/rtpengine/rtpengine.c
@@ -1829,6 +1829,7 @@ static int build_rtpp_socks(int lmode, int rtest) {
 		rtpe_reload_lock_get(rtpp_list->rset_lock);
 		for (pnode=rtpp_list->rn_first; pnode!=0; pnode = pnode->rn_next) {
 			char *hostname;
+			char *hp;
 
 			if (pnode->rn_umode == 0) {
 				rtpp_socks[pnode->idx] = -1;
@@ -1860,11 +1861,23 @@ static int build_rtpp_socks(int lmode, int rtest) {
 			if (cp == NULL || *cp == '\0')
 				cp = CPORT;
 
+			if(pnode->rn_umode == 6) {
+				hp = strrchr(hostname, ']');
+				if(hp != NULL)
+					*hp = '\0';
+
+				hp = hostname;
+				if(*hp == '[')
+					hp++;
+			} else {
+				hp = hostname;
+			}
+
 			memset(&hints, 0, sizeof(hints));
 			hints.ai_flags = 0;
 			hints.ai_family = (pnode->rn_umode == 6) ? AF_INET6 : AF_INET;
 			hints.ai_socktype = SOCK_DGRAM;
-			if ((n = getaddrinfo(hostname, cp, &hints, &res)) != 0) {
+			if ((n = getaddrinfo(hp, cp, &hints, &res)) != 0) {
 				LM_ERR("%s\n", gai_strerror(n));
 				pkg_free(hostname);
 				rtpp_socks[pnode->idx] = -1;




More information about the sr-dev mailing list