Skip to content

Commit

Permalink
Merge pull request #180 from flaviojs/ensure-ip_listen_range-getsockn…
Browse files Browse the repository at this point in the history
…ame-is-ok

Ensure the getsockname call in ip_listen_range is ok.
  • Loading branch information
grossmj authored Mar 16, 2024
2 parents f0932c6 + bd20a1f commit 37e438f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions common/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@ int ip_listen_range(char *ip_addr,int port_start,int port_end,int *port,

if ((fd = ip_socket_bind(res)) >= 0) {
st_len = sizeof(st);
getsockname(fd,(struct sockaddr *)&st,&st_len);
if (getsockname(fd,(struct sockaddr *)&st,&st_len) != 0) {
close(fd);
continue;
}
*port = ip_socket_get_port((struct sockaddr *)&st);
goto done;
}
Expand Down Expand Up @@ -677,7 +680,10 @@ int ip_listen_range(char *ip_addr,int port_start,int port_end,int *port,

if ((fd = ip_socket_bind(&sin,sock_type)) >= 0) {
len = sizeof(sin);
getsockname(fd,(struct sockaddr *)&sin,&len);
if (getsockname(fd,(struct sockaddr *)&sin,&len) != 0) {
close(fd);
continue;
}
*port = ntohs(sin.sin_port);
return(fd);
}
Expand Down

0 comments on commit 37e438f

Please sign in to comment.