diff -r 11dbbf1043f4 src/main.c
--- a/src/main.c	Tue Jul 01 09:39:38 2008 +0200
+++ b/src/main.c	Wed Jul 02 12:59:50 2008 +0200
@@ -163,6 +163,8 @@ main(int argc, char *argv[])
   /* Using PID as random seed */
   srandom(getpid());
 
+  /* Init widely used statics */
+  memset(&all_zero, 0, sizeof(union olsr_ip_addr));
 
   /*
    * Set configfile name and
diff -r 11dbbf1043f4 src/olsr.c
--- a/src/olsr.c	Tue Jul 01 09:39:38 2008 +0200
+++ b/src/olsr.c	Wed Jul 02 12:59:50 2008 +0200
@@ -85,6 +85,7 @@ static struct pcf *pcf_list;
 static struct pcf *pcf_list;
 
 static olsr_u16_t message_seqno;
+union olsr_ip_addr all_zero;
 
 /**
  *Initialize the message sequence number as a random value
diff -r 11dbbf1043f4 src/olsr.h
--- a/src/olsr.h	Tue Jul 01 09:39:38 2008 +0200
+++ b/src/olsr.h	Wed Jul 02 12:59:50 2008 +0200
@@ -49,6 +49,8 @@ extern olsr_bool changes_neighborhood;
 extern olsr_bool changes_neighborhood;
 extern olsr_bool changes_hna;
 extern olsr_bool changes_force;
+
+extern union olsr_ip_addr all_zero;
 
 void
 register_pcf(int (*)(int, int, int));
diff -r 11dbbf1043f4 src/olsr_spf.c
--- a/src/olsr_spf.c	Tue Jul 01 09:39:38 2008 +0200
+++ b/src/olsr_spf.c	Wed Jul 02 12:59:50 2008 +0200
@@ -360,10 +360,25 @@ olsr_calculate_routing_table (void)
     tc->hops = 0;
   } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
 
+
+  /*
+   * Check if there was a change in the main IP address.
+   * Bail if there is no main IP address.
+   */
+  olsr_change_myself_tc();
+  if (!tc_myself) {
+
+    /*
+     * All gone now. Flush all routes.
+     */
+    olsr_update_rib_routes();
+    olsr_update_kernel_routes();
+    return;
+  }
+
   /*
    * zero ourselves and add us to the candidate tree.
    */
-  olsr_change_myself_tc();
   tc_myself->path_cost = ZERO_ROUTE_COST;
   olsr_spf_add_cand_tree(&cand_tree, tc_myself);
 
diff -r 11dbbf1043f4 src/tc_set.c
--- a/src/tc_set.c	Tue Jul 01 09:39:38 2008 +0200
+++ b/src/tc_set.c	Wed Jul 02 12:59:50 2008 +0200
@@ -136,6 +136,13 @@ olsr_add_tc_entry(union olsr_ip_addr *ad
   struct ipaddr_str buf;
 #endif
   struct tc_entry *tc;
+
+  /*
+   * Safety net against loss of the last main IP address.
+   */
+  if (ipequal(&olsr_cnf->main_addr, &all_zero)) {
+    return NULL;
+  }
 
 #ifdef DEBUG
   OLSR_PRINTF(1, "TC: add entry %s\n", olsr_ip_to_string(&buf, adr));
