mysql8.4/community-mysql-netdevname.patch
2024-02-05 16:59:12 +01:00

59 lines
1.8 KiB
Diff

diff -up mysql-5.6.10/mysys/my_gethwaddr.c.orig mysql-5.6.10/mysys/my_gethwaddr.c
--- mysql-5.6.10/mysys/my_gethwaddr.c.orig 2013-01-22 17:54:49.000000000 +0100
+++ mysql-5.6.10/mysys/my_gethwaddr.c 2013-02-19 15:19:48.632960900 +0100
@@ -68,27 +68,47 @@ err:
#include <sys/ioctl.h>
#include <net/ethernet.h>
+#define MAX_IFS 64
+
my_bool my_gethwaddr(uchar *to)
{
int fd, res= 1;
struct ifreq ifr;
char zero_array[ETHER_ADDR_LEN] = {0};
+ struct ifconf ifc;
+ struct ifreq ifs[MAX_IFS], *ifri, *ifend;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
goto err;
- memset(&ifr, 0, sizeof(ifr));
- strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
+ ifc.ifc_len = sizeof(ifs);
+ ifc.ifc_req = ifs;
+ if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
+ {
+ close(fd);
+ goto err;
+ }
- do
+ memcpy(to, zero_array, ETHER_ADDR_LEN);
+
+ ifend = ifs + (ifc.ifc_len / sizeof(struct ifreq));
+ for (ifri = ifc.ifc_req; ifri < ifend; ifri++)
{
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
+ if (ifri->ifr_addr.sa_family == AF_INET)
{
- memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
- res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1;
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, ifri->ifr_name, sizeof(ifr.ifr_name));
+
+ /* Get HW address */
+ if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
+ {
+ memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
+ if (!(res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1))
+ break;
+ }
}
- } while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
+ }
close(fd);
err: