title: How to get ethtool settings?
body: <p>Please, help me get ethtool settings (speed, duplex, autoneg). </p>
  
  <p>If I use ETHTOOL_GSET, I get ethtool settings. But in ethtool.h written to use ETHTOOL_GLINKSETTINGS instead of ETHTOOL_GSET. I don't know how to use ETHTOOL_GLINKSETTINGS.</p>
  
  <p><strong>ETHTOOL_GSET</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;net/if.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;linux/ethtool.h&gt;
  #include &lt;linux/sockios.h&gt;
  
  int main()
  {
      int s; // socket
      int r; // result
  
      struct ifreq ifReq;
      strncpy(ifReq.ifr_name, "enp3s0", sizeof(ifReq.ifr_name));
  
      struct ethtool_cmd ethtoolCmd;
      ethtoolCmd.cmd = ETHTOOL_GSET;
      ifReq.ifr_data = &amp;ethtoolCmd;
  
      s = socket(AF_INET, SOCK_DGRAM, 0);
      if (s != -1)
      {
          r = ioctl(s, SIOCETHTOOL, &amp;ifReq);
          if (s != -1)
          {
              printf("%s | ethtool_cmd.speed = %i \n", ifReq.ifr_name, ethtoolCmd.speed);
              printf("%s | ethtool_cmd.duplex = %i \n", ifReq.ifr_name, ethtoolCmd.duplex);
              printf("%s | ethtool_cmd.autoneg = %i \n", ifReq.ifr_name, ethtoolCmd.autoneg);
          }
          else
              printf("Error #r");
  
          close(s);
      }
      else
          printf("Error #s");
  
      return 0;
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>enp3s0 | ethtool_cmd.speed = 1000 
  enp3s0 | ethtool_cmd.duplex = 1
  enp3s0 | ethtool_cmd.autoneg = 1
  </code></pre>
  
  <p><strong>ETHTOOL_GLINKSETTINGS</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;net/if.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;linux/ethtool.h&gt;
  #include &lt;linux/sockios.h&gt;
  
  int main()
  {
      int s; // socket
      int r; // result
  
      struct ifreq ifReq;
      strncpy(ifReq.ifr_name, "enp3s0", sizeof(ifReq.ifr_name));
  
      struct ethtool_link_settings ethtoolLinkSettings;
      ethtoolLinkSettings.cmd = ETHTOOL_GLINKSETTINGS;
      ifReq.ifr_data = &amp;ethtoolLinkSettings;
  
      s = socket(AF_INET, SOCK_DGRAM, 0);
      if (s != -1)
      {
          r = ioctl(s, SIOCETHTOOL, &amp;ifReq);
          if (s != -1)
          {
              printf("%s | ethtool_link_settings.speed = %i \n", ifReq.ifr_name, ethtoolLinkSettings.speed);
              printf("%s | ethtool_link_settings.duplex = %i \n", ifReq.ifr_name, ethtoolLinkSettings.duplex);
              printf("%s | ethtool_link_settings.autoneg = %i \n", ifReq.ifr_name, ethtoolLinkSettings.autoneg);
          }
          else
              printf("Error #r");
  
          close(s);
      }
      else
          printf("Error #s");
  
      return 0;
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>enp3s0 | ethtool_link_settings.speed = 0 
  enp3s0 | ethtool_link_settings.duplex = 45
  enp3s0 | ethtool_link_settings.autoneg = 0
  </code></pre>
  
  <p>Why ETHTOOL_GLINKSETTINGS return incorrect values? What is the problem?</p>