Index: src/core/netif.c
===================================================================
--- src/core/netif.c	(revision 980)
+++ src/core/netif.c	(working copy)
@@ -226,6 +226,30 @@
   netif_set_gw(netif, gw);
 }
 
+#if LWIP_TCP
+static void netif_remove_pcbs(struct netif *netif){
+  struct tcp_pcb *pcb;
+  pcb = tcp_active_pcbs;
+  while (pcb != NULL) {
+    /* PCB bound to current local interface address? */
+    if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))
+#if LWIP_AUTOIP
+      /* connections to link-local addresses must persist (RFC3927 ch. 1.9) */
+      && !ip_addr_islinklocal(&(pcb->local_ip))
+#endif /* LWIP_AUTOIP */
+      ) {
+      /* this connection must be aborted */
+      struct tcp_pcb *next = pcb->next;
+      LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_remove_pcbs: aborting TCP pcb %p\n", (void *)pcb));
+      tcp_abort(pcb);
+      pcb = next;
+    } else {
+      pcb = pcb->next;
+    }
+  }
+}
+#endif
+
 /**
  * Remove a network interface from the list of lwIP netifs.
  *
@@ -238,6 +262,10 @@
     return;
   }
 
+#if LWIP_TCP
+  netif_remove_pcbs(netif);
+#endif
+
 #if LWIP_IGMP
   /* stop IGMP processing */
   if (netif->flags & NETIF_FLAG_IGMP) {
@@ -325,31 +353,13 @@
   /* TODO: Handling of obsolete pcbs */
   /* See:  http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */
 #if LWIP_TCP
-  struct tcp_pcb *pcb;
   struct tcp_pcb_listen *lpcb;
 
   /* address is actually being changed? */
   if (ipaddr && (ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0) {
     /* extern struct tcp_pcb *tcp_active_pcbs; defined by tcp.h */
     LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
-    pcb = tcp_active_pcbs;
-    while (pcb != NULL) {
-      /* PCB bound to current local interface address? */
-      if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))
-#if LWIP_AUTOIP
-        /* connections to link-local addresses must persist (RFC3927 ch. 1.9) */
-        && !ip_addr_islinklocal(&(pcb->local_ip))
-#endif /* LWIP_AUTOIP */
-        ) {
-        /* this connection must be aborted */
-        struct tcp_pcb *next = pcb->next;
-        LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb));
-        tcp_abort(pcb);
-        pcb = next;
-      } else {
-        pcb = pcb->next;
-      }
-    }
+    netif_remove_pcbs(netif);
     for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
       /* PCB bound to current local interface address? */
       if ((!(ip_addr_isany(&(lpcb->local_ip)))) &&
