MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / rtpengine_connect_node

Function rtpengine_connect_node

modules/rtpengine/rtpengine.c:1784–1866  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1782}
1783
1784static inline int rtpengine_connect_node(struct rtpe_node *pnode)
1785{
1786 int n;
1787 char *cp, *start, *end;
1788 char *hostname;
1789 struct addrinfo hints, *res;
1790
1791 if (pnode->rn_umode == 0) {
1792 rtpe_socks[pnode->idx] = -1;
1793 return 1;
1794 }
1795
1796 start = pnode->rn_address;
1797
1798 cp = strrchr(pnode->rn_address, ':');
1799 if (cp == NULL) {
1800 /* no explicit port, use the default one */
1801 cp = CPORT;
1802 end = start + strlen(pnode->rn_address);
1803 } else {
1804 end = cp++;
1805 if (pnode->rn_umode == 6) {
1806 /* if IPv6 mode, port should be right after ] */
1807 if (end > start && *(end - 1) != ']') {
1808 /* if it is not, then it is part of the address */
1809 cp = CPORT;
1810 end = start + strlen(pnode->rn_address);
1811 }
1812 }
1813 }
1814 if (pnode->rn_umode == 6 && *start == '[') {
1815 start++;
1816 if (end > start && *(end - 1) == ']')
1817 end--;
1818 }
1819
1820 hostname = (char*)pkg_malloc(end - start + 1);
1821 if (hostname==NULL) {
1822 LM_ERR("no more pkg memory\n");
1823 return 0;
1824 }
1825 memcpy(hostname, start, end - start);
1826 hostname[end-start] = '\0';
1827
1828 memset(&hints, 0, sizeof(hints));
1829 hints.ai_flags = 0;
1830 hints.ai_family = (pnode->rn_umode == 6) ? AF_INET6 : AF_INET;
1831 hints.ai_socktype = SOCK_DGRAM;
1832 if ((n = getaddrinfo(hostname, cp, &hints, &res)) != 0) {
1833 LM_ERR("%s\n", gai_strerror(n));
1834 pkg_free(hostname);
1835 return 0;
1836 }
1837 pkg_free(hostname);
1838
1839 if (res->ai_addrlen > sizeof(pnode->ai_addr)) {
1840 LM_ERR("RTP proxy address is too large\n");
1841 freeaddrinfo(res);

Callers 3

connect_rtpenginesFunction · 0.85
send_rtpe_commandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected