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

Function connect_rtpp_node

modules/rtpproxy/rtppn_connect.c:63–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63int connect_rtpp_node(struct rtpp_node *pnode)
64{
65 int n, s;
66 char *cp, *hostname = NULL;
67 struct addrinfo hints, *res;
68 struct sockaddr_un sau;
69
70 assert(pnode->rn_umode != CM_RTPIO);
71 /*
72 * This is UDP, TCP, UDP6 or TCP6. Detect host and port; lookup host;
73 * do connect() in order to specify peer address
74 */
75 if (pnode->rn_umode != CM_CUNIX) {
76 hostname = (char*)pkg_malloc(sizeof(char) * (strlen(pnode->rn_address) + 1));
77 if (hostname == NULL) {
78 LM_ERR("no more pkg memory\n");
79 goto e0;
80 }
81 strcpy(hostname, pnode->rn_address);
82
83 cp = strrchr(hostname, ':');
84 if (cp != NULL) {
85 *cp = '\0';
86 cp++;
87 }
88 if (cp == NULL || *cp == '\0')
89 cp = DEFAULT_CPORT;
90
91 memset(&hints, 0, sizeof(hints));
92 hints.ai_flags = 0;
93 hints.ai_family = (pnode->rn_umode == CM_UDP6 || pnode->rn_umode == CM_TCP6) ? AF_INET6 : AF_INET;
94 hints.ai_socktype = CM_STREAM(pnode) ? SOCK_STREAM : SOCK_DGRAM;
95 if ((n = getaddrinfo(hostname, cp, &hints, &res)) != 0) {
96 LM_ERR("%s\n", gai_strerror(n));
97 goto e1;
98 }
99 } else {
100 memset(&sau, 0, sizeof(sau));
101 hints = (struct addrinfo) {
102 .ai_family = AF_LOCAL,
103 .ai_socktype = SOCK_STREAM,
104 .ai_protocol = 0,
105 .ai_addr = (struct sockaddr *)&sau,
106 .ai_addrlen = sizeof(sau),
107 };
108 res = &hints;
109 sau.sun_family = AF_LOCAL;
110 strncpy(sau.sun_path, pnode->rn_address, sizeof(sau.sun_path) - 1);
111#ifdef HAVE_SOCKADDR_SA_LEN
112 sau.sun_len = strlen(sau.sun_path);
113#endif
114 }
115
116 s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
117 if (s == -1) {
118 LM_ERR("can't create socket\n");
119 goto e2;
120 }

Callers 2

connect_rtpproxiesFunction · 0.85
send_rtpp_commandFunction · 0.85

Calls 1

try_connectFunction · 0.85

Tested by

no test coverage detected