/* 同一段代码对两个不同版本的 Linux 的工作方式不同,输出如下
Linux mamma-linux 2.6.27.19-5-default #1 SMP 2009-02-28 04:40:21 +0100 x86_64 x86_64 x86_64 GNU/Linux 输出:返回 false
Linux inblrbuildserver01 3.0.13-0.27-default #1 SMP 2012 年 2 月 15 日星期三 13:33:49 UTC (d73692b) x86_64 x86_64 x86_64 GNU/Linux
输出:速度为:100Mbps */
#include <sys/socket.h>#
##include <sys/ioctl.h> ##
###include <netinet/in.h>###
####include <linux/sockios.h>####
#####include <linux/if.h>#####
#####include <linux/ethtool.h> #####
######include <string.h>######
#######include <stdlib.h>#######
//#include <linux/wireless.h>
########include<iostream>#######
using namespace std;
int main (int argc, char **argv)
{
int sock;
struct ifreq ifr;
struct ethtool_cmd edata;
int rc;
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock < 0) {
// perror("socket");
exit(1);
}
strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));
ifr.ifr_data = &edata;
edata.cmd = ETHTOOL_GSET;
rc = ioctl(sock, SIOCETHTOOL, &ifr);
if (rc < 0) {
// perror("ioctl");
cout<<" Returning false " <<endl;
exit(1);
}
switch (edata.speed) {
case SPEED_10: printf(" SPEED is : 10Mbps\n"); break;
case SPEED_100: printf("SPEED is : 100Mbps\n"); break;
case SPEED_1000: printf("1Gbps\n"); break;
case SPEED_2500: printf("2.5Gbps\n"); break;
case SPEED_10000: printf("10Gbps\n"); break;
default: printf("Speed returned is %d\n", edata.speed);
}
return (0);
}
/*Linux mammo-linux 2.6.27.19-5-default #1 SMP 2009-02-28 04:40:21 +0100 x86_64 x86_64 x86_64 GNU/Linux
Returning false
Linux inblrbuildserver01 3.0.13-0.27-default #1 SMP Wed Feb 15 13:33:49 UTC 2012 (d73692b) x86_64 x86_64 x86_64 GNU/Linux
SPEED is : 100Mbps
*/
有人可以帮忙吗???