X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsolaris%2Fdevice.c;h=a258e34e34f8097cd1c28c43a7eca74771d9fd20;hb=075e6828a7533e7daa790225f17aa6bb39703278;hp=c66db906db929266359d707b63ceb61a13d0a25d;hpb=f02d3ed3e135b5326003e7f69f8331ff6a3cc219;p=meshlink diff --git a/src/solaris/device.c b/src/solaris/device.c index c66db906..a258e34e 100644 --- a/src/solaris/device.c +++ b/src/solaris/device.c @@ -1,7 +1,7 @@ /* device.c -- Interaction with Solaris tun device Copyright (C) 2001-2005 Ivo Timmermans, - 2001-2006 Guus Sliepen + 2001-2009 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,13 +31,14 @@ #include "logger.h" #include "net.h" #include "utils.h" +#include "xalloc.h" #define DEFAULT_DEVICE "/dev/tun" int device_fd = -1; char *device = NULL; char *iface = NULL; -char *device_info = NULL; +static char *device_info = NULL; static int device_total_in = 0; static int device_total_out = 0; @@ -50,7 +51,7 @@ bool setup_device(void) { cp(); if(!get_config_string(lookup_config(config_tree, "Device"), &device)) - device = DEFAULT_DEVICE; + device = xstrdup(DEFAULT_DEVICE); if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) { logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno)); @@ -98,7 +99,7 @@ bool setup_device(void) { } if(!get_config_string(lookup_config(config_tree, "Interface"), &iface)) - asprintf(&iface, "tun%d", ppa); + xasprintf(&iface, "tun%d", ppa); device_info = _("Solaris tun device"); @@ -111,14 +112,17 @@ void close_device(void) { cp(); close(device_fd); + + free(device); + free(iface); } bool read_packet(vpn_packet_t *packet) { - int lenin; + int inlen; cp(); - if((lenin = read(device_fd, packet->data + 14, MTU - 14)) <= 0) { + if((inlen = read(device_fd, packet->data + 14, MTU - 14)) <= 0) { logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info, device, strerror(errno)); return false; @@ -140,7 +144,7 @@ bool read_packet(vpn_packet_t *packet) { return false; } - packet->len = lenin + 14; + packet->len = inlen + 14; device_total_in += packet->len;