Merge "Pass in the length to pseudo checksum functions" into jb-mr2-dev
diff --git a/Android.mk b/Android.mk
index c31a361..2d1b3a6 100644
--- a/Android.mk
+++ b/Android.mk
@@ -5,7 +5,7 @@
 
 LOCAL_C_INCLUDES := external/libnl-headers
 LOCAL_STATIC_LIBRARIES := libnl_2
-LOCAL_SHARED_LIBRARIES := libcutils
+LOCAL_SHARED_LIBRARIES := libcutils liblog
 
 LOCAL_MODULE := clatd
 
diff --git a/clatd.c b/clatd.c
index ea8363c..edd8a2d 100644
--- a/clatd.c
+++ b/clatd.c
@@ -192,25 +192,26 @@
  * tunnel - tun device data
  */
 void configure_tun_ip(const struct tun_data *tunnel) {
-  struct in_addr default_4;
   int status;
 
-  default_4.s_addr = INADDR_ANY;
+  // Configure the interface before bringing it up. As soon as we bring the interface up, the
+  // framework will be notified and will assume the interface's configuration has been finalized.
+  status = add_address(tunnel->device4, AF_INET, &Global_Clatd_Config.ipv4_local_subnet,
+      32, &Global_Clatd_Config.ipv4_local_subnet);
+  if(status < 0) {
+    logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_address(4) failed: %s",strerror(-status));
+    exit(1);
+  }
 
   if((status = if_up(tunnel->device6, Global_Clatd_Config.mtu)) < 0) {
     logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_up(6) failed: %s",strerror(-status));
     exit(1);
   }
+
   if((status = if_up(tunnel->device4, Global_Clatd_Config.ipv4mtu)) < 0) {
     logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_up(4) failed: %s",strerror(-status));
     exit(1);
   }
-  status = add_address(tunnel->device4, AF_INET, &Global_Clatd_Config.ipv4_local_subnet,
-      32, &Global_Clatd_Config.ipv4_local_subnet);
-  if(status < 0) {
-    logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_address(4) failed: %s",strerror(-status));
-    exit(1);
-  }
 
   configure_tun_ipv6(tunnel);
 }