mirror of
https://github.com/clearml/dropbear
synced 2025-05-15 09:05:52 +00:00
Small cleanups of netio allocated port
This commit is contained in:
parent
934cc87db3
commit
8b0fdf8010
22
netio.c
22
netio.c
@ -459,7 +459,7 @@ int dropbear_listen(const char* address, const char* port,
|
|||||||
struct linger linger;
|
struct linger linger;
|
||||||
int val;
|
int val;
|
||||||
int sock;
|
int sock;
|
||||||
u_int16_t *allocated_lport_p = NULL;
|
uint16_t *allocated_lport_p = NULL;
|
||||||
int allocated_lport = 0;
|
int allocated_lport = 0;
|
||||||
|
|
||||||
TRACE(("enter dropbear_listen"))
|
TRACE(("enter dropbear_listen"))
|
||||||
@ -504,18 +504,15 @@ int dropbear_listen(const char* address, const char* port,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* When listening on server-assigned-port 0
|
||||||
* when listening on server-assigned-port 0
|
|
||||||
* the assigned ports may differ for address families (v4/v6)
|
* the assigned ports may differ for address families (v4/v6)
|
||||||
* causing problems for tcpip-forward
|
* causing problems for tcpip-forward.
|
||||||
* caller can do a get_socket_address to discover assigned-port
|
* Caller can do a get_socket_address to discover assigned-port
|
||||||
* hence, use same port for all address families
|
* hence, use same port for all address families */
|
||||||
*/
|
allocated_lport = 0;
|
||||||
|
|
||||||
nsock = 0;
|
nsock = 0;
|
||||||
for (res = res0; res != NULL && nsock < sockcount;
|
for (res = res0; res != NULL && nsock < sockcount;
|
||||||
res = res->ai_next) {
|
res = res->ai_next) {
|
||||||
|
|
||||||
if (allocated_lport > 0) {
|
if (allocated_lport > 0) {
|
||||||
if (AF_INET == res->ai_family) {
|
if (AF_INET == res->ai_family) {
|
||||||
allocated_lport_p = &((struct sockaddr_in *)res->ai_addr)->sin_port;
|
allocated_lport_p = &((struct sockaddr_in *)res->ai_addr)->sin_port;
|
||||||
@ -526,11 +523,8 @@ int dropbear_listen(const char* address, const char* port,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get a socket */
|
/* Get a socket */
|
||||||
socks[nsock] = socket(res->ai_family, res->ai_socktype,
|
socks[nsock] = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||||
res->ai_protocol);
|
|
||||||
|
|
||||||
sock = socks[nsock]; /* For clarity */
|
sock = socks[nsock]; /* For clarity */
|
||||||
|
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
err = errno;
|
err = errno;
|
||||||
TRACE(("socket() failed"))
|
TRACE(("socket() failed"))
|
||||||
@ -554,7 +548,6 @@ int dropbear_listen(const char* address, const char* port,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
set_sock_nodelay(sock);
|
set_sock_nodelay(sock);
|
||||||
|
|
||||||
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
|
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
|
||||||
@ -576,7 +569,6 @@ int dropbear_listen(const char* address, const char* port,
|
|||||||
}
|
}
|
||||||
|
|
||||||
*maxfd = MAX(*maxfd, sock);
|
*maxfd = MAX(*maxfd, sock);
|
||||||
|
|
||||||
nsock++;
|
nsock++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user