Imported Upstream version 0.3.2
[debian/uanytun.git] / src / bsd / tun.c
index f193668..21d16a4 100644 (file)
@@ -20,8 +20,9 @@
  *  This file is part of uAnytun.
  *
  *  uAnytun is free software: you can redistribute it and/or modify
  *  This file is part of uAnytun.
  *
  *  uAnytun is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 3 as
- *  published by the Free Software Foundation.
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  any later version.
  *
  *  uAnytun is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *
  *  uAnytun is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -313,36 +314,31 @@ void tun_do_ifconfig(tun_device_t* dev)
   if(!dev || !dev->actual_name_ || !dev->net_addr_ || !dev->net_mask_)
     return;
 
   if(!dev || !dev->actual_name_ || !dev->net_addr_ || !dev->net_mask_)
     return;
 
-
-  char* command = NULL;
-  char* netmask;
   char* end;
   if(dev->type_ == TYPE_TAP) {
 #if defined(__GNUC__) && defined(__OpenBSD__)
   char* end;
   if(dev->type_ == TYPE_TAP) {
 #if defined(__GNUC__) && defined(__OpenBSD__)
-    end = " link0";
+    end = "link0";
 #elif defined(__GNUC__) && defined(__FreeBSD__)
 #elif defined(__GNUC__) && defined(__FreeBSD__)
-    end = " up";
+    end = "up";
 #elif defined(__GNUC__) && defined(__NetBSD__)
 #elif defined(__GNUC__) && defined(__NetBSD__)
-    end = "";
+    end = NULL;
 #else
  #error This Device works just for OpenBSD, FreeBSD or NetBSD
 #endif
   }
   else
 #else
  #error This Device works just for OpenBSD, FreeBSD or NetBSD
 #endif
   }
   else
-    end = " up";
+    end = "up";
 
 
-  asprintf(&command, "/sbin/ifconfig %s %s netmask %s mtu %d%s", dev->actual_name_, dev->net_addr_,
-                                                                 dev->net_mask_, dev->mtu_, end);
-  if(!command) {
+  char* mtu_str = NULL;
+  asprintf(&mtu_str, "%d", dev->mtu_);
+  if(!mtu_str) {
     log_printf(ERROR, "Execution of ifconfig failed");
     return;
   }
 
     log_printf(ERROR, "Execution of ifconfig failed");
     return;
   }
 
-  int result = system(command);
-  if(result == -1)
-    log_printf(ERROR, "Execution of ifconfig failed");
-  else
-    log_printf(NOTICE, "ifconfig returned %d", WEXITSTATUS(result));
+  char* const argv[] = { "/sbin/ifconfig", dev->actual_name_, dev->net_addr_, "netmask", dev->net_mask_, "mtu", mtu_str, end, NULL };
+  char* const evp[] = { NULL };
+  uanytun_exec("/sbin/ifconfig", argv, evp);
 
 
-  free(command);
+  free(mtu_str);
 }
 }