3 #include <linux/sockios.h>
12 uint32_t wireless_bitrate(const char *ifname
)
15 uint32_t rate_in_mbit
;
18 sock
= af_socket(AF_INET
);
20 memset(&iwr
, 0, sizeof(iwr
));
21 strlcpy(iwr
.ifr_name
, ifname
, IFNAMSIZ
);
23 ret
= ioctl(sock
, SIOCGIWRATE
, &iwr
);
25 rate_in_mbit
= iwr
.u
.bitrate
.value
/ 1000000;
34 int wireless_sigqual(const char *ifname
, struct iw_statistics
*stats
)
39 sock
= af_socket(AF_INET
);
41 memset(&iwr
, 0, sizeof(iwr
));
42 strlcpy(iwr
.ifr_name
, ifname
, IFNAMSIZ
);
44 iwr
.u
.data
.pointer
= (caddr_t
) stats
;
45 iwr
.u
.data
.length
= sizeof(*stats
);
48 ret
= ioctl(sock
, SIOCGIWSTATS
, &iwr
);
55 int wireless_rangemax_sigqual(const char *ifname
)
57 int ret
, sock
, sigqual
;
59 struct iw_range iwrange
;
61 sock
= af_socket(AF_INET
);
63 memset(&iwrange
, 0, sizeof(iwrange
));
65 memset(&iwr
, 0, sizeof(iwr
));
66 strlcpy(iwr
.ifr_name
, ifname
, IFNAMSIZ
);
68 iwr
.u
.data
.pointer
= (caddr_t
) &iwrange
;
69 iwr
.u
.data
.length
= sizeof(iwrange
);
72 ret
= ioctl(sock
, SIOCGIWRANGE
, &iwr
);
74 sigqual
= iwrange
.max_qual
.qual
;
83 uint32_t ethtool_bitrate(const char *ifname
)
88 struct ethtool_cmd ecmd
;
90 sock
= af_socket(AF_INET
);
92 memset(&ecmd
, 0, sizeof(ecmd
));
94 memset(&ifr
, 0, sizeof(ifr
));
95 strlcpy(ifr
.ifr_name
, ifname
, IFNAMSIZ
);
97 ecmd
.cmd
= ETHTOOL_GSET
;
98 ifr
.ifr_data
= (char *) &ecmd
;
100 ret
= ioctl(sock
, SIOCETHTOOL
, &ifr
);
106 bitrate
= ethtool_cmd_speed(&ecmd
);
107 if (bitrate
== SPEED_UNKNOWN
)
115 int ethtool_link(const char *ifname
)
119 struct ethtool_value ecmd
;
121 sock
= af_socket(AF_INET
);
123 memset(&ecmd
, 0, sizeof(ecmd
));
125 memset(&ifr
, 0, sizeof(ifr
));
126 strlcpy(ifr
.ifr_name
, ifname
, IFNAMSIZ
);
128 ecmd
.cmd
= ETHTOOL_GLINK
;
129 ifr
.ifr_data
= (char *) &ecmd
;
131 ret
= ioctl(sock
, SIOCETHTOOL
, &ifr
);
141 int ethtool_drvinf(const char *ifname
, struct ethtool_drvinfo
*drvinf
)
146 sock
= af_socket(AF_INET
);
148 memset(drvinf
, 0, sizeof(*drvinf
));
150 memset(&ifr
, 0, sizeof(ifr
));
151 strlcpy(ifr
.ifr_name
, ifname
, IFNAMSIZ
);
153 drvinf
->cmd
= ETHTOOL_GDRVINFO
;
154 ifr
.ifr_data
= (char *) drvinf
;
156 ret
= ioctl(sock
, SIOCETHTOOL
, &ifr
);