1
/*同一段代碼的工作方式不同的兩種不同版本的Linux &那裏放出來,如下的ioctl(襪子,SIOCETHTOOL,與IFR)爲什麼它返回-1所有的時間
Linux的乳房專用的Linux 2.6.27.19 -5-默認的#1 SMP 2009-02-28 4時40分21秒+0100 x86_64的x86_64的x86_64的GNU/Linux的 輸出地說: 返回false
的Linux inblrbuildserver01 3.0.13-0.27默認的#1 SMP星期三二月15 13:33:49 UTC 2012(d73692b)x86_64 x86_64 x86_64 GNU/Linux
輸出: SPEED是: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
*/
可以爲這個任意一個幫助???
請格式化你的代碼和文本。另外,閱讀關於錯誤的ioctl手冊頁,將相關代碼和結果添加到您的問題中。 – 2013-05-07 15:54:55