人生如逆旅,我亦是行人!江湖人称wsjjeremy.blog.chinaunix.net
ubuntuer
全部博文(930)
intern(3)
string(19)
正则表达式(5)
2011年(60)
2010年(220)
2009年(371)
2008年(279)
baocheng
nba76ers
renjian2
qq576709
mcn304
zibuyule
西农魔峰
曾德标
zhuqing_
shanck
tendy
moshangx
wb123456
smile124
hjshajsh
chenhong
bzhao
python16
分类: LINUX
2009-10-14 10:57:41
#include <sys/types.h>#include <sys/socket.h>#include <sys/ioctl.h>#include <net/if.h>#include <linux/sockios.h>#include <linux/types.h>#include <netinet/in.h>#include <stdlib.h>#include <string.h>#include <stdio.h>struct mii_data{ __u16 phy_id; __u16 reg_num; __u16 val_in; __u16 val_out;};int main(int argc, char *argv[]){ struct mii_data *mii = NULL; int sockfd; struct ifreq ifr; if(argc != 2) { printf( "Useage: argv[0] ethX.\n" ); return 0; } if((sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { perror("socket"); return -1; } memset(&ifr, '\0', sizeof(ifr)); strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1); if(ioctl(sockfd, SIOCGMIIPHY, &ifr) == -1) { perror("ioct SIOCGMIIPHY"); return -1; } mii = (struct mii_data*)&ifr.ifr_data; mii->reg_num = 0x01; if(ioctl(sockfd, SIOCGMIIREG, &ifr) == -1) { perror("ioctl SIOCGMIIREG"); return -1; } if(mii->val_out & 0x0004) printf("link up\n"); else printf("link down\n"); close(sockfd); return 0;}
上一篇:浮点数在计算机中的存储表示
下一篇:MySql index analysis and optimize
登录 注册