diff --git a/src/api/api_msg.c b/src/api/api_msg.c index d4413f4e..165ffdf4 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -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: diff --git a/src/core/udp.c b/src/core/udp.c index 5b5e0fb3..d7e49777 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -28,7 +28,7 @@ * * Author: Adam Dunkels * - * $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;