Query the Linux device for its MAC address.
[tinc] / src / linux / device.c
index 6ed1622..3b384d4 100644 (file)
@@ -105,15 +105,25 @@ static bool setup_device(void) {
 
        logger(DEBUG_ALWAYS, LOG_INFO, "%s is a %s", device, device_info);
 
+       if(ifr.ifr_flags & IFF_TAP) {
+               struct ifreq ifr_mac;
+               if(!ioctl(device_fd, SIOCGIFHWADDR, &ifr_mac))
+                       memcpy(mymac.x, ifr_mac.ifr_hwaddr.sa_data, ETH_ALEN);
+               else
+                       logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get MAC address of %s: %s", device, strerror(errno));
+       }
+
        return true;
 }
 
 static void close_device(void) {
        close(device_fd);
+       device_fd = -1;
 
-       free(type);
-       free(device);
-       free(iface);
+       free(type); type = NULL;
+       free(device); device = NULL;
+       free(iface); iface = NULL;
+       device_info = NULL;
 }
 
 static bool read_packet(vpn_packet_t *packet) {