Blame SOURCES/mysql-netdevname.patch

6f9931
diff -up mysql-5.5.15/mysys/my_gethwaddr.c.netdevname mysql-5.5.15/mysys/my_gethwaddr.c
6f9931
--- mysql-5.5.15/mysys/my_gethwaddr.c.netdevname	2011-07-13 21:09:02.000000000 +0200
6f9931
+++ mysql-5.5.15/mysys/my_gethwaddr.c	2011-11-01 12:32:35.356119715 +0100
6f9931
@@ -68,28 +68,47 @@ err:
6f9931
 #include <sys/ioctl.h>
6f9931
 #include <net/ethernet.h>
6f9931
 
6f9931
+#define MAX_IFS 64
6f9931
+
6f9931
 my_bool my_gethwaddr(uchar *to)
6f9931
 {
6f9931
   int fd, res= 1;
6f9931
   struct ifreq ifr;
6f9931
   char zero_array[ETHER_ADDR_LEN] = {0};
6f9931
+  struct ifconf ifc;
6f9931
+  struct ifreq ifs[MAX_IFS], *ifri, *ifend;
6f9931
 
6f9931
   fd = socket(AF_INET, SOCK_DGRAM, 0);
6f9931
   if (fd < 0)
6f9931
     goto err;
6f9931
 
6f9931
-  bzero(&ifr, sizeof(ifr));
6f9931
-  strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
6f9931
+  ifc.ifc_len = sizeof(ifs);
6f9931
+  ifc.ifc_req = ifs;
6f9931
+  if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
6f9931
+  {
6f9931
+    close(fd);
6f9931
+    goto err;
6f9931
+  }
6f9931
+
6f9931
+  memcpy(to, zero_array, ETHER_ADDR_LEN);
6f9931
 
6f9931
-  do
6f9931
+  ifend = ifs + (ifc.ifc_len / sizeof(struct ifreq));
6f9931
+  for (ifri = ifc.ifc_req; ifri < ifend; ifri++)
6f9931
   {
6f9931
-    if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
6f9931
+    if (ifri->ifr_addr.sa_family == AF_INET)
6f9931
     {
6f9931
-      memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
6f9931
-      res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1;
6f9931
+      bzero(&ifr, sizeof(ifr));
6f9931
+      strncpy(ifr.ifr_name, ifri->ifr_name, sizeof(ifr.ifr_name));
6f9931
+      
6f9931
+      /* Get HW address */
6f9931
+      if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
6f9931
+      {
6f9931
+        memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
6f9931
+        if (!(res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1))
6f9931
+          break;
6f9931
+      }
6f9931
     }
6f9931
-  } while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
6f9931
-
6f9931
+  }
6f9931
   close(fd);
6f9931
 err:
6f9931
   return res;