21 #include <sys/ioctl.h> 22 #include <sys/types.h> 24 #include <linux/ethtool.h> 25 #include <linux/sockios.h> 31 #define doIoctl(ifr, errorMsg) \ 32 if ( ::ioctl( sockfd_->fd, SIOCETHTOOL, &ifr ) < 0 ) \ 33 SENF_THROW_SYSTEM_EXCEPTION("EthernetController: " errorMsg) 49 struct ethtool_cmd edata;
50 edata.cmd = ETHTOOL_GSET;
51 ifr.ifr_data =
reinterpret_cast<caddr_t
>(&edata);
52 doIoctl(ifr,
"Could not discover speed of ethernet interface");
61 struct ethtool_cmd edata;
62 edata.cmd = ETHTOOL_GSET;
63 ifr.ifr_data =
reinterpret_cast<caddr_t
>(&edata);
64 doIoctl(ifr,
"Could not discover duplex mode of ethernet interface");
65 switch (edata.duplex) {
74 <<
"(" << unsigned(edata.duplex) <<
")";
86 static const std::string duplexModes[] = {
"half",
"full",
"unknown" };
87 return duplexModes[
std::min(
unsigned(mode),2u)];
96 struct ethtool_value edata;
97 edata.cmd = ETHTOOL_GLINK;
98 ifr.ifr_data =
reinterpret_cast<caddr_t
>(&edata);
99 doIoctl(ifr,
"Could not discover link status of ethernet interface");
107 struct ethtool_value edata;
108 edata.cmd = ETHTOOL_NWAY_RST;
109 ifr.ifr_data =
reinterpret_cast<caddr_t
>(&edata);
110 doIoctl(ifr,
"nWayReset failed.");
118 struct ethtool_ringparam edata;
119 memset(&edata, 0,
sizeof(edata));
120 edata.cmd = ETHTOOL_SRINGPARAM;
121 edata.rx_pending = rx;
122 edata.tx_pending = tx;
123 ifr.ifr_data =
reinterpret_cast<caddr_t
>(&edata);
124 doIoctl(ifr,
"setRingParam failed.");
132 struct ethtool_ringparam edata;
133 memset(&edata, 0,
sizeof(edata));
134 edata.cmd = ETHTOOL_GRINGPARAM;
135 ifr.ifr_data =
reinterpret_cast<caddr_t
>(&edata);
136 doIoctl(ifr,
"getRingParam failed.");
137 return std::make_pair(edata.rx_pending,edata.tx_pending);
144 struct ethtool_eee edata;
145 memset(&edata, 0,
sizeof(edata));
146 edata.cmd = ETHTOOL_SEEE;
147 edata.eee_enabled = on;
148 ifr.ifr_data =
reinterpret_cast<caddr_t
>(&edata);
149 doIoctl(ifr,
"setEEE failed.");
157 struct ethtool_eee edata;
158 memset(&edata, 0,
sizeof(edata));
159 edata.cmd = ETHTOOL_GEEE;
160 ifr.ifr_data =
reinterpret_cast<caddr_t
>(&edata);
161 doIoctl(ifr,
"getEEE failed.");
162 return edata.eee_enabled;
WLANController public header.
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
std::string duplexAsString() const
void ifrName(ifreq &ifr) const
Duplex_mode duplex() const
EthernetController(std::string const &interface_name)
#define doIoctl(ifr, errorMsg)
std::pair< std::uint32_t, std::uint32_t > ringSize()