#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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;
}
阅读(1162) | 评论(0) | 转发(1) |