summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-06-24 01:25:37 +0000
committerChristian Pointner <equinox@anytun.org>2009-06-24 01:25:37 +0000
commitd0331983dca42bf6f98e2283ba8478b067512f8a (patch)
treea23deeecdfb52329729dc6d957c0ccdeaeb33445
parentlinux tun device now uses uanytun_exec for ifconfig call (diff)
bsd tun device now also uses uanytun_exec
-rw-r--r--src/bsd/tun.c26
-rw-r--r--src/log.c2
2 files changed, 11 insertions, 17 deletions
diff --git a/src/bsd/tun.c b/src/bsd/tun.c
index f193668..e2736ec 100644
--- a/src/bsd/tun.c
+++ b/src/bsd/tun.c
@@ -313,36 +313,30 @@ void tun_do_ifconfig(tun_device_t* dev)
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__)
- end = " link0";
+ end = "link0";
#elif defined(__GNUC__) && defined(__FreeBSD__)
- end = " up";
+ end = "up";
#elif defined(__GNUC__) && defined(__NetBSD__)
- end = "";
+ end = NULL;
#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;
}
- 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[] = { dev->actual_name_, dev->net_addr_, "netmask", dev->net_mask_, "mtu", mtu_str, end, NULL };
+ uanytun_exec("/sbin/ifconfig", argv, NULL);
- free(command);
+ free(mtu_str);
}
diff --git a/src/log.c b/src/log.c
index 847baf7..8f7deb3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -250,7 +250,7 @@ void log_print_hex_dump(log_prio_t prio, const u_int8_t* buf, u_int32_t len)
for(i=0; i < len; i++) {
if(((i+1)*3) >= (MSG_LENGTH_MAX - offset))
break;
- sprintf(ptr, "%02X ", buf[i]);
+ snprintf(ptr, 3, "%02X ", buf[i]);
ptr+=3;
}
}