diff --git a/src/core/raw.c b/src/core/raw.c index 243333e4..c630537f 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -235,7 +235,10 @@ raw_bind(struct raw_pcb *pcb, const ip_addr_t *ipaddr) /** * @ingroup raw_raw - * Bind a RAW PCB. + * Bind an RAW PCB to a specific netif. + * After calling this function, all packets received via this PCB + * are guaranteed to have come in via the specified netif, and all + * outgoing packets will go out via the specified netif. * * @param pcb RAW PCB to be bound with netif. * @param netif netif to bind to. Can be NULL. diff --git a/src/core/tcp.c b/src/core/tcp.c index 6d17e090..bcbf2693 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -643,6 +643,9 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) /** * @ingroup tcp_raw * Binds the connection to a netif and IP address. + * After calling this function, all packets received via this PCB + * are guaranteed to have come in via the specified netif, and all + * outgoing packets will go out via the specified netif. * * @param pcb the tcp_pcb to bind. * @param netif the netif to bind to. Can be NULL. @@ -926,21 +929,18 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, /* check if we have a route to the remote host */ netif = ip_route(&pcb->local_ip, &pcb->remote_ip); } - if (netif == NULL) { /* Don't even try to send a SYN packet if we have no route since that will fail. */ return ERR_RTE; } + /* check if local IP has been assigned to pcb, if not, get one */ if (ip_addr_isany(&pcb->local_ip)) { - /* no local IP address set, yet. */ const ip_addr_t *local_ip = ip_netif_get_local_ip(netif, ipaddr); - if (local_ip != NULL) { - /* Use the address as local address of the pcb. */ - ip_addr_copy(pcb->local_ip, *local_ip); - } else { + if (local_ip == NULL) { return ERR_RTE; } + ip_addr_copy(pcb->local_ip, *local_ip); } #if LWIP_IPV6 && LWIP_IPV6_SCOPES diff --git a/src/core/udp.c b/src/core/udp.c index 949d6e7d..f6ade7dd 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -1007,6 +1007,9 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) /** * @ingroup udp_raw * Bind an UDP PCB to a specific netif. + * After calling this function, all packets received via this PCB + * are guaranteed to have come in via the specified netif, and all + * outgoing packets will go out via the specified netif. * * @param pcb UDP PCB to be bound. * @param netif netif to bind udp pcb to. Can be NULL.