mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-12-26 03:16:18 +00:00
dns: Slightly improve dns_alloc_random_port implementation
Having the variable namining ret for a pointer makes the code looks odd, ret looks like a value variable. Rename ret to pcb. Also simplify the code in the do {} while() loop. Signed-off-by: Axel Lin <axel.lin@ingics.com>
This commit is contained in:
parent
2903b476c7
commit
be7ae5e36b
@ -800,28 +800,28 @@ static struct udp_pcb*
|
||||
dns_alloc_random_port(void)
|
||||
{
|
||||
err_t err;
|
||||
struct udp_pcb* ret;
|
||||
struct udp_pcb* pcb;
|
||||
|
||||
ret = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
if (ret == NULL) {
|
||||
pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
if (pcb == NULL) {
|
||||
/* out of memory, have to reuse an existing pcb */
|
||||
return NULL;
|
||||
}
|
||||
do {
|
||||
u16_t port = (u16_t)DNS_RAND_TXID();
|
||||
if (!DNS_PORT_ALLOWED(port)) {
|
||||
if (DNS_PORT_ALLOWED(port)) {
|
||||
err = udp_bind(pcb, IP_ANY_TYPE, port);
|
||||
} else {
|
||||
/* this port is not allowed, try again */
|
||||
err = ERR_USE;
|
||||
continue;
|
||||
}
|
||||
err = udp_bind(ret, IP_ANY_TYPE, port);
|
||||
} while (err == ERR_USE);
|
||||
if (err != ERR_OK) {
|
||||
udp_remove(ret);
|
||||
udp_remove(pcb);
|
||||
return NULL;
|
||||
}
|
||||
udp_recv(ret, dns_recv, NULL);
|
||||
return ret;
|
||||
udp_recv(pcb, dns_recv, NULL);
|
||||
return pcb;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user