From 5743b11925b508930b2d1001b302ad7f4e44293c Mon Sep 17 00:00:00 2001 From: goldsimon Date: Sun, 25 Nov 2007 18:37:34 +0000 Subject: [PATCH] Check state == CLOSED in tcp_bind and tcp_connect to prevent binding/connecting twice (using LWIP_ERROR: can be disabled) --- src/core/tcp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index 34e460f2..a794c685 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -256,6 +256,8 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) { struct tcp_pcb *cpcb; + LWIP_ERROR("tcp_connect: can only bind in state CLOSED", pcb->state == CLOSED, return ERR_ISCONN); + if (port == 0) { port = tcp_new_port(); } @@ -343,7 +345,7 @@ tcp_listen(struct tcp_pcb *pcb) { struct tcp_pcb_listen *lpcb; - LWIP_ERROR("pcb not already connected", pcb->state == CLOSED, return NULL); + LWIP_ERROR("tcp_listen: pcb already connected", pcb->state == CLOSED, return NULL); /* already listening? */ if (pcb->state == LISTEN) { @@ -474,6 +476,8 @@ tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port, err_t ret; u32_t iss; + LWIP_ERROR("tcp_connect: can only connected from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN); + LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port)); if (ipaddr != NULL) { pcb->remote_ip = *ipaddr;