Don't allow multiple binds to the same UDP port/address pair.Closes bug #1896

This commit is contained in:
jani 2003-01-21 14:09:31 +00:00
parent 39edc69514
commit 16434f0d01
2 changed files with 14 additions and 4 deletions

View File

@ -272,7 +272,7 @@ do_bind(struct api_msg_msg *msg)
case NETCONN_UDPNOCHKSUM:
/* FALLTHROUGH */
case NETCONN_UDP:
udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
msg->conn->err = udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
break;
#endif /* LWIP_UDP */
case NETCONN_TCP:

View File

@ -28,7 +28,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: udp.c,v 1.9 2003/01/17 15:16:33 likewise Exp $
* $Id: udp.c,v 1.10 2003/01/21 14:09:31 jani Exp $
*/
/*-----------------------------------------------------------------------------------*/
@ -396,8 +396,6 @@ err_t
udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
{
struct udp_pcb *ipcb;
ip_addr_set(&pcb->local_ip, ipaddr);
pcb->local_port = port;
/* Insert UDP PCB into the list of active UDP PCBs. */
for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
@ -405,7 +403,19 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
/* Already on the list, just return. */
return ERR_OK;
}
if (ipcb->local_port == port) {
if(ip_addr_isany(&(ipcb->local_ip)) ||
ip_addr_isany(ipaddr) ||
ip_addr_cmp(&(ipcb->local_ip), ipaddr)) {
/* Port/IP pair already bound */
return ERR_USE;
}
}
}
ip_addr_set(&pcb->local_ip, ipaddr);
pcb->local_port = port;
/* We need to place the PCB on the list. */
pcb->next = udp_pcbs;
udp_pcbs = pcb;