X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fbsd%2Fdevice.c;h=54282626212fd5a3dd49290caadb1888de1ae223;hb=ab13c14a1480561bb9f59ccfbbd6045e0484ce9c;hp=303e9b6840de8d29163c720354670714fcbc2147;hpb=d7f6737cfcae75e8c2f522c68aaedee0519a6131;p=tinc diff --git a/src/bsd/device.c b/src/bsd/device.c index 303e9b68..54282626 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -147,7 +147,7 @@ static bool setup_device(void) { } } else { #ifdef HAVE_NET_IF_UTUN_H - if(strncmp(device, "utun", 4) == 0 || strncmp(device, "/dev/utun", 9) == 0) + if(device && (strncmp(device, "utun", 4) == 0 || strncmp(device, "/dev/utun", 9) == 0)) device_type = DEVICE_TYPE_UTUN; else #endif @@ -349,13 +349,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 +369,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 +430,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;