--- src/core/ipv4/ip.c	Mon Jan 19 23:14:56 1970
+++ src/core/ipv4/ip.c	Mon Jan 19 23:14:56 1970
@@ -121,7 +121,7 @@
  * @return the netif on which to send to reach dest
  */
 struct netif *
-ip_route(ip_addr_t *dest)
+ip_route(struct ip_pcb *pcb, ip_addr_t *dest)
 {
   struct netif *netif;
 
@@ -130,11 +130,13 @@
     /* network mask matches? */
     if (netif_is_up(netif)) {
       if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
+    	  if (!pcb || !pcb->local_ip.addr || ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
         /* return netif on which to forward IP packet */
         return netif;
       }
     }
   }
+  }
   if ((netif_default == NULL) || (!netif_is_up(netif_default))) {
     LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
       ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
@@ -754,7 +756,7 @@
      gets altered as the packet is passed down the stack */
   LWIP_ASSERT("p->ref == 1", p->ref == 1);
 
-  if ((netif = ip_route(dest)) == NULL) {
+  if ((netif = ip_route(NULL, dest)) == NULL) {
     LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
       ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
     IP_STATS_INC(ip.rterr);
@@ -794,7 +796,7 @@
      gets altered as the packet is passed down the stack */
   LWIP_ASSERT("p->ref == 1", p->ref == 1);
 
-  if ((netif = ip_route(dest)) == NULL) {
+  if ((netif = ip_route(NULL, dest)) == NULL) {
     LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
       ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
     IP_STATS_INC(ip.rterr);
--- src/core/raw.c	Mon Jan 19 23:14:56 1970
+++ src/core/raw.c	Mon Jan 19 23:14:56 1970
@@ -233,7 +233,7 @@
     }
   }
 
-  if ((netif = ip_route(ipaddr)) == NULL) {
+  if ((netif = ip_route((struct ip_pcb*)pcb, ipaddr)) == NULL) {
     LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
       ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr)));
     /* free any temporary header pbuf allocated by pbuf_header() */
--- src/core/tcp.c	Mon Jan 19 23:14:56 1970
+++ src/core/tcp.c	Mon Jan 19 23:14:56 1970
@@ -666,7 +666,7 @@
   /* check if we have a route to the remote host */
   if (ip_addr_isany(&(pcb->local_ip))) {
     /* no local IP address set, yet. */
-    struct netif *netif = ip_route(&(pcb->remote_ip));
+    struct netif *netif = ip_route((struct ip_pcb*)pcb, &(pcb->remote_ip));
     if (netif == NULL) {
       /* Don't even try to send a SYN packet if we have no route
          since that will fail. */
@@ -1481,7 +1481,7 @@
   u16_t mss_s;
   struct netif *outif;
 
-  outif = ip_route(addr);
+  outif = ip_route(NULL, addr);
   if ((outif != NULL) && (outif->mtu != 0)) {
     mss_s = outif->mtu - IP_HLEN - TCP_HLEN;
     /* RFC 1122, chap 4.2.2.6:
--- src/core/tcp_out.c	Mon Jan 19 23:14:56 1970
+++ src/core/tcp_out.c	Mon Jan 19 23:14:56 1970
@@ -1087,7 +1087,7 @@
   /* If we don't have a local IP address, we get one by
      calling ip_route(). */
   if (ip_addr_isany(&(pcb->local_ip))) {
-    netif = ip_route(&(pcb->remote_ip));
+    netif = ip_route((struct ip_pcb*)pcb, &(pcb->remote_ip));
     if (netif == NULL) {
       return;
     }
--- src/core/udp.c	Mon Jan 19 23:14:56 1970
+++ src/core/udp.c	Mon Jan 19 23:14:56 1970
@@ -180,7 +180,7 @@
 #if IP_SOF_BROADCAST_RECV
            (broadcast && (pcb->so_options & SOF_BROADCAST)))) {
 #else  /* IP_SOF_BROADCAST_RECV */
-           (broadcast))) {
+           (broadcast && (ip_addr_cmp(&(pcb->local_ip), &(inp->ip_addr)) || ip_addr_isany(&pcb->local_ip))))) {
 #endif /* IP_SOF_BROADCAST_RECV */
         local_match = 1;
         if ((uncon_pcb == NULL) && 
@@ -436,7 +436,7 @@
 #if LWIP_IGMP
   netif = ip_route((ip_addr_ismulticast(dst_ip))?(&(pcb->multicast_ip)):(dst_ip));
 #else
-  netif = ip_route(dst_ip);
+  netif = ip_route((struct ip_pcb*)pcb, dst_ip);
 #endif /* LWIP_IGMP */
 
   /* no outgoing network interface could be found? */
--- inc/ipv4/lwip/ip.h	Mon Jan 19 23:14:56 1970
+++ inc/ipv4/lwip/ip.h	Mon Jan 19 23:14:56 1970
@@ -169,7 +169,7 @@
 extern ip_addr_t current_iphdr_dest;
 
 #define ip_init() /* Compatibility define, not init needed. */
-struct netif *ip_route(ip_addr_t *dest);
+struct netif *ip_route(struct ip_pcb *pcb, ip_addr_t *dest);
 err_t ip_input(struct pbuf *p, struct netif *inp);
 err_t ip_output(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
        u8_t ttl, u8_t tos, u8_t proto);
