chiark / gitweb /
udev - link-setup - expose ID_NET_DRIVER
[elogind.git] / src / udev / net / ethtool-util.c
index 4fad52b469f28c6ef3216ad726bec04dc6e9d586..aaba94c2fb71c3da5194f8a482c9e4b91ab09129 100644 (file)
@@ -63,19 +63,43 @@ int ethtool_connect(int *ret) {
         return 0;
 }
 
+int ethtool_get_driver(int fd, const char *ifname, char **ret) {
+        struct ifreq ifr;
+        struct ethtool_drvinfo ecmd;
+        int r;
+
+        zero(ecmd);
+        ecmd.cmd = ETHTOOL_GDRVINFO;
+
+        zero(ifr);
+        strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
+        ifr.ifr_data = (void *)&ecmd;
+
+        r = ioctl(fd, SIOCETHTOOL, &ifr);
+        if (r < 0)
+                return -errno;
+
+        *ret = strdup(ecmd.driver);
+        if (!*ret)
+                return -ENOMEM;
+
+        return 0;
+}
+
 int ethtool_set_speed(int fd, const char *ifname, unsigned int speed, Duplex duplex)
 {
         struct ifreq ifr;
         struct ethtool_cmd ecmd;
-        bool need_update;
+        bool need_update = false;
         int r;
 
         if (speed == 0 && duplex == _DUP_INVALID)
                 return 0;
 
-        memset(&ecmd, 0x00, sizeof(struct ethtool_cmd));
+        zero(ecmd);
         ecmd.cmd = ETHTOOL_GSET;
-        memset(&ifr, 0x00, sizeof(struct ifreq));
+
+        zero(ifr);
         strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
         ifr.ifr_data = (void *)&ecmd;
 
@@ -119,15 +143,16 @@ int ethtool_set_speed(int fd, const char *ifname, unsigned int speed, Duplex dup
 int ethtool_set_wol(int fd, const char *ifname, WakeOnLan wol) {
         struct ifreq ifr;
         struct ethtool_wolinfo ecmd;
-        bool need_update;
+        bool need_update = false;
         int r;
 
         if (wol == _WOL_INVALID)
                 return 0;
 
-        memset(&ecmd, 0x00, sizeof(struct ethtool_wolinfo));
+        zero(ecmd);
         ecmd.cmd = ETHTOOL_GWOL;
-        memset(&ifr, 0x00, sizeof(struct ifreq));
+
+        zero(ifr);
         strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
         ifr.ifr_data = (void *)&ecmd;