mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-09-17 20:24:24 +00:00
tcp_bind/tcp_connect: Omit checking for the same port if no port specified
No port specified means to use a random port. tcp_new_port() returns a new (free) local TCP port number on success. So in this case we don't need iterating all lists to test if the port number is used, tcp_new_port() alreay ensures the port is not used. Signed-off-by: Axel Lin <axel.lin@ingics.com>
This commit is contained in:
parent
b68e801975
commit
5056d375f2
@ -464,8 +464,7 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
|
||||
if (port == 0) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Check if the address already is in use (on all lists) */
|
||||
for (i = 0; i < max_pcb_list; i++) {
|
||||
for (cpcb = *tcp_pcb_lists[i]; cpcb != NULL; cpcb = cpcb->next) {
|
||||
@ -489,6 +488,7 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ip_addr_isany(ipaddr)) {
|
||||
ip_addr_set(&pcb->local_ip, ipaddr);
|
||||
@ -785,7 +785,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
|
||||
if (pcb->local_port == 0) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#if SO_REUSE
|
||||
if (ip_get_option(pcb, SOF_REUSEADDR)) {
|
||||
/* Since SOF_REUSEADDR allows reusing a local address, we have to make sure
|
||||
@ -807,6 +807,8 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
|
||||
}
|
||||
}
|
||||
#endif /* SO_REUSE */
|
||||
}
|
||||
|
||||
iss = tcp_next_iss();
|
||||
pcb->rcv_nxt = 0;
|
||||
pcb->snd_nxt = iss;
|
||||
|
Loading…
Reference in New Issue
Block a user