@@ -197,15 +197,14 @@ static int host_lookup(const char *host, int family, uint8_t pdn_id,
197197 return 0 ;
198198}
199199
200- static int client_connect (struct download_client * dl , const char * host ,
201- struct sockaddr * sa , int * fd )
200+ static int client_connect (struct download_client * dl )
202201{
203202 int err ;
204203 int type ;
205204 uint16_t port ;
206205 socklen_t addrlen ;
207206
208- err = url_parse_proto (host , & dl -> proto , & type );
207+ err = url_parse_proto (dl -> host , & dl -> proto , & type );
209208 if (err ) {
210209 LOG_DBG ("Protocol not specified, defaulting to HTTP(S)" );
211210 type = SOCK_STREAM ;
@@ -234,7 +233,7 @@ static int client_connect(struct download_client *dl, const char *host,
234233 return - EINVAL ;
235234 }
236235
237- err = url_parse_port (host , & port );
236+ err = url_parse_port (dl -> host , & port );
238237 if (err ) {
239238 switch (dl -> proto ) {
240239 case IPPROTO_TLS_1_2 :
@@ -253,61 +252,61 @@ static int client_connect(struct download_client *dl, const char *host,
253252 LOG_DBG ("Port not specified, using default: %d" , port );
254253 }
255254
256- switch (sa -> sa_family ) {
255+ switch (dl -> remote_addr . sa_family ) {
257256 case AF_INET6 :
258- SIN6 (sa )-> sin6_port = htons (port );
257+ SIN6 (& dl -> remote_addr )-> sin6_port = htons (port );
259258 addrlen = sizeof (struct sockaddr_in6 );
260259 break ;
261260 case AF_INET :
262- SIN (sa )-> sin_port = htons (port );
261+ SIN (& dl -> remote_addr )-> sin_port = htons (port );
263262 addrlen = sizeof (struct sockaddr_in );
264263 break ;
265264 default :
266265 return - EAFNOSUPPORT ;
267266 }
268267
269268 LOG_DBG ("family: %d, type: %d, proto: %d" ,
270- sa -> sa_family , type , dl -> proto );
269+ dl -> remote_addr . sa_family , type , dl -> proto );
271270
272- * fd = socket (sa -> sa_family , type , dl -> proto );
273- if (* fd < 0 ) {
271+ dl -> fd = socket (dl -> remote_addr . sa_family , type , dl -> proto );
272+ if (dl -> fd < 0 ) {
274273 LOG_ERR ("Failed to create socket, err %d" , errno );
275274 return - errno ;
276275 }
277276
278277 if (dl -> config .pdn_id ) {
279- err = socket_pdn_id_set (* fd , dl -> config .pdn_id );
278+ err = socket_pdn_id_set (dl -> fd , dl -> config .pdn_id );
280279 if (err ) {
281280 goto cleanup ;
282281 }
283282 }
284283
285284 if ((dl -> proto == IPPROTO_TLS_1_2 || dl -> proto == IPPROTO_DTLS_1_2 )
286285 && (dl -> config .sec_tag != -1 )) {
287- err = socket_sectag_set (* fd , dl -> config .sec_tag );
286+ err = socket_sectag_set (dl -> fd , dl -> config .sec_tag );
288287 if (err ) {
289288 goto cleanup ;
290289 }
291290
292291 if (dl -> config .set_tls_hostname ) {
293- err = socket_tls_hostname_set (* fd , host );
292+ err = socket_tls_hostname_set (dl -> fd , dl -> host );
294293 if (err ) {
295294 goto cleanup ;
296295 }
297296 }
298297 }
299298
300299 /* Set socket timeout, if configured */
301- err = socket_timeout_set (* fd , type );
300+ err = socket_timeout_set (dl -> fd , type );
302301 if (err ) {
303302 goto cleanup ;
304303 }
305304
306- LOG_INF ("Connecting to %s" , log_strdup (host ));
305+ LOG_INF ("Connecting to %s" , log_strdup (dl -> host ));
307306 LOG_DBG ("fd %d, addrlen %d, fam %s, port %d" ,
308- * fd , addrlen , str_family (sa -> sa_family ), port );
307+ dl -> fd , addrlen , str_family (dl -> remote_addr . sa_family ), port );
309308
310- err = connect (* fd , sa , addrlen );
309+ err = connect (dl -> fd , & dl -> remote_addr , addrlen );
311310 if (err ) {
312311 LOG_ERR ("Unable to connect, errno %d" , errno );
313312 err = - errno ;
@@ -316,8 +315,8 @@ static int client_connect(struct download_client *dl, const char *host,
316315cleanup :
317316 if (err ) {
318317 /* Unable to connect, close socket */
319- close (* fd );
320- * fd = -1 ;
318+ close (dl -> fd );
319+ dl -> fd = -1 ;
321320 }
322321
323322 return err ;
@@ -600,7 +599,6 @@ int download_client_connect(struct download_client *client, const char *host,
600599 const struct download_client_cfg * config )
601600{
602601 int err ;
603- struct sockaddr sa ;
604602
605603 if (client == NULL || host == NULL || config == NULL ) {
606604 return - EINVAL ;
@@ -619,10 +617,10 @@ int download_client_connect(struct download_client *client, const char *host,
619617 err = 0 ;
620618 /* Attempt IPv6 connection if configured, fallback to IPv4 */
621619 if (IS_ENABLED (CONFIG_DOWNLOAD_CLIENT_IPV6 )) {
622- err = host_lookup (host , AF_INET6 , config -> pdn_id , & sa );
620+ err = host_lookup (host , AF_INET6 , config -> pdn_id , & client -> remote_addr );
623621 }
624622 if (err || !IS_ENABLED (CONFIG_DOWNLOAD_CLIENT_IPV6 )) {
625- err = host_lookup (host , AF_INET , config -> pdn_id , & sa );
623+ err = host_lookup (host , AF_INET , config -> pdn_id , & client -> remote_addr );
626624 }
627625
628626 if (err ) {
@@ -632,7 +630,7 @@ int download_client_connect(struct download_client *client, const char *host,
632630 client -> config = * config ;
633631 client -> host = host ;
634632
635- err = client_connect (client , host , & sa , & client -> fd );
633+ err = client_connect (client );
636634 if (client -> fd < 0 ) {
637635 return err ;
638636 }
0 commit comments