@@ -134,28 +134,47 @@ controlfd_init_ifsun(const struct rtpp_cfg *cfsp, struct rtpp_ctrl_sock *csp)
134134}
135135
136136static int
137- controlfd_init_udp (const struct rtpp_cfg * cfsp , struct rtpp_ctrl_sock * csp )
137+ controlfd_setbindhost (const struct rtpp_cfg * cfsp , struct rtpp_ctrl_sock * csp ,
138+ struct sockaddr * ifsin , int af )
138139{
139- struct sockaddr * ifsin ;
140- char * cp , * tcp = NULL ;
141- int controlfd , so_rcvbuf , i , r ;
140+ const char * cp , * bindhost , * port ;
141+ char * bindhost_buf ;
142+ size_t bindhost_len ;
143+ int r ;
142144
143145 cp = strrchr (csp -> cmd_sock , ':' );
144146 if (cp != NULL ) {
145- * cp = '\0' ;
146- tcp = cp ;
147- cp ++ ;
147+ bindhost_len = cp - csp -> cmd_sock ;
148+ bindhost_buf = alloca (bindhost_len + 1 );
149+ memcpy (bindhost_buf , csp -> cmd_sock , bindhost_len );
150+ bindhost_buf [bindhost_len ] = '\0' ;
151+ bindhost = bindhost_buf ;
152+ port = cp + 1 ;
153+ } else {
154+ bindhost = csp -> cmd_sock ;
155+ port = CPORT ;
148156 }
149- if (cp == NULL || * cp == '\0' )
150- cp = CPORT ;
151- csp -> port_ctl = atoi (cp );
157+ if (* port == '\0' )
158+ port = CPORT ;
159+ csp -> port_ctl = atoi (port );
160+ r = setbindhost (ifsin , af , bindhost , port , cfsp -> no_resolve );
161+ if (r != 0 ) {
162+ warnx ("setbindhost failed" );
163+ return (-1 );
164+ }
165+ return (0 );
166+ }
167+
168+ static int
169+ controlfd_init_udp (const struct rtpp_cfg * cfsp , struct rtpp_ctrl_sock * csp )
170+ {
171+ struct sockaddr * ifsin ;
172+ int controlfd , so_rcvbuf , i , r ;
173+
152174 i = (csp -> type == RTPC_UDP6 ) ? AF_INET6 : AF_INET ;
153175 ifsin = sstosa (& csp -> bindaddr );
154- r = setbindhost (ifsin , i , csp -> cmd_sock , cp , cfsp -> no_resolve );
155- if (tcp != NULL )
156- * tcp = ':' ;
176+ r = controlfd_setbindhost (cfsp , csp , ifsin , i );
157177 if (r != 0 ) {
158- warnx ("setbindhost failed" );
159178 return (-1 );
160179 }
161180 controlfd = socket (i , SOCK_DGRAM , 0 );
@@ -179,25 +198,12 @@ static int
179198controlfd_init_tcp (const struct rtpp_cfg * cfsp , struct rtpp_ctrl_sock * csp )
180199{
181200 struct sockaddr * ifsin ;
182- char * cp , * tcp = NULL ;;
183201 int controlfd , so_rcvbuf , i , r ;
184202
185- cp = strrchr (csp -> cmd_sock , ':' );
186- if (cp != NULL ) {
187- * cp = '\0' ;
188- tcp = cp ;
189- cp ++ ;
190- }
191- if (cp == NULL || * cp == '\0' )
192- cp = CPORT ;
193- csp -> port_ctl = atoi (cp );
194203 i = (csp -> type == RTPC_TCP6 ) ? AF_INET6 : AF_INET ;
195204 ifsin = sstosa (& csp -> bindaddr );
196- r = setbindhost (ifsin , i , csp -> cmd_sock , cp , cfsp -> no_resolve );
197- if (tcp != NULL )
198- * tcp = ':' ;
205+ r = controlfd_setbindhost (cfsp , csp , ifsin , i );
199206 if (r != 0 ) {
200- warnx ("setbindhost failed" );
201207 return (-1 );
202208 }
203209 controlfd = socket (i , SOCK_STREAM , 0 );
0 commit comments