Clear Ethernet header when reading packets from a tun device.
[tinc] / src / linux / device.c
index 93d4b41..f770f7f 100644 (file)
@@ -73,6 +73,10 @@ static bool setup_device(void) {
                return false;
        }
 
+#ifdef FD_CLOEXEC
+       fcntl(device_fd, F_SETFD, FD_CLOEXEC);
+#endif
+
 #ifdef HAVE_LINUX_IF_TUN_H
        /* Ok now check if this is an old ethertap or a new tun/tap thingie */
 
@@ -151,6 +155,7 @@ static bool read_packet(vpn_packet_t *packet) {
                                return false;
                        }
 
+                       memset(packet->data, 0, 12);
                        packet->len = lenin + 10;
                        break;
                case DEVICE_TYPE_TAP:
@@ -206,7 +211,7 @@ static bool write_packet(vpn_packet_t *packet) {
                        }
                        break;
                case DEVICE_TYPE_ETHERTAP:
-                       *(short int *)(packet->data - 2) = packet->len;
+                       memcpy(packet->data - 2, &packet->len, 2);
 
                        if(write(device_fd, packet->data - 2, packet->len + 2) < 0) {
                                logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device,