mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-12-27 06:14:09 +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)
|
dns_alloc_random_port(void)
|
||||||
{
|
{
|
||||||
err_t err;
|
err_t err;
|
||||||
struct udp_pcb* ret;
|
struct udp_pcb* pcb;
|
||||||
|
|
||||||
ret = udp_new_ip_type(IPADDR_TYPE_ANY);
|
pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||||
if (ret == NULL) {
|
if (pcb == NULL) {
|
||||||
/* out of memory, have to reuse an existing pcb */
|
/* out of memory, have to reuse an existing pcb */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
u16_t port = (u16_t)DNS_RAND_TXID();
|
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 */
|
/* this port is not allowed, try again */
|
||||||
err = ERR_USE;
|
err = ERR_USE;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
err = udp_bind(ret, IP_ANY_TYPE, port);
|
|
||||||
} while (err == ERR_USE);
|
} while (err == ERR_USE);
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
udp_remove(ret);
|
udp_remove(pcb);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
udp_recv(ret, dns_recv, NULL);
|
udp_recv(pcb, dns_recv, NULL);
|
||||||
return ret;
|
return pcb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user