Releasing 1.1pre15.
[tinc] / src / bsd / device.c
index 0d41c96..4a63e84 100644 (file)
@@ -1,7 +1,7 @@
 /*
     device.c -- Interaction BSD tun/tap device
     Copyright (C) 2001-2005 Ivo Timmermans,
-                  2001-2016 Guus Sliepen <guus@tinc-vpn.org>
+                  2001-2017 Guus Sliepen <guus@tinc-vpn.org>
                   2009      Grzegorz Dymarek <gregd72002@googlemail.com>
 
     This program is free software; you can redistribute it and/or modify
@@ -198,18 +198,19 @@ static bool setup_device(void) {
 
        // Guess what the corresponding interface is called
 
-       char *realname;
+       char *realname = NULL;
 
 #if defined(HAVE_FDEVNAME)
-       realname = fdevname(device_fd) ? : device;
+       realname = fdevname(device_fd);
 #elif defined(HAVE_DEVNAME)
        struct stat buf;
        if(!fstat(device_fd, &buf))
-               realname = devname(buf.st_rdev, S_IFCHR) ? : device;
-#else
-       realname = device;
+               realname = devname(buf.st_rdev, S_IFCHR);
 #endif
 
+       if(!realname)
+               realname = device;
+
        if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
                iface = xstrdup(strrchr(realname, '/') ? strrchr(realname, '/') + 1 : realname);
        else if(strcmp(iface, strrchr(realname, '/') ? strrchr(realname, '/') + 1 : realname))
@@ -349,13 +350,13 @@ static bool read_packet(vpn_packet_t *packet) {
 
                case DEVICE_TYPE_UTUN:
                case DEVICE_TYPE_TUNIFHEAD: {
-                       if((inlen = read(device_fd, packet->data + 10, MTU - 10)) <= 0) {
+                       if((inlen = read(device_fd, DATA(packet) + 10, MTU - 10)) <= 0) {
                                logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading from %s %s: %s", device_info,
                                           device, strerror(errno));
                                return false;
                        }
 
-                       switch (packet->data[14] >> 4) {
+                       switch (DATA(packet)[14] >> 4) {
                                case 4:
                                        DATA(packet)[12] = 0x08;
                                        DATA(packet)[13] = 0x00;
@@ -369,7 +370,7 @@ static bool read_packet(vpn_packet_t *packet) {
                                default:
                                        logger(DEBUG_TRAFFIC, LOG_ERR,
                                                           "Unknown IP version %d while reading packet from %s %s",
-                                                          packet->data[14] >> 4, device_info, device);
+                                                          DATA(packet)[14] >> 4, device_info, device);
                                        return false;
                        }
 
@@ -430,9 +431,9 @@ static bool write_packet(vpn_packet_t *packet) {
                                        return false;
                        }
 
-                       memcpy(packet->data + 10, &type, sizeof type);
+                       memcpy(DATA(packet) + 10, &type, sizeof type);
 
-                       if(write(device_fd, packet->data + 10, packet->len - 10) < 0) {
+                       if(write(device_fd, DATA(packet) + 10, packet->len - 10) < 0) {
                                logger(DEBUG_ALWAYS, LOG_ERR, "Can't write to %s %s: %s", device_info, device,
                                           strerror(errno));
                                return false;