#include #include #include #include #include #include #include #include #include #include #include #define ETHTOOL_GSET 0x00000001 #define ETHTOOL_GWOL 0x00000005 #define ETHTOOL_GMSGLVL 0x00000007 #define ETHTOOL_GLINK 0x0000000a #define SOPASS_MAX 6 typedef __uint32_t __u32; typedef __uint16_t __u16; typedef __uint8_t __u8; static char *devname = NULL; /* This should work for both 32 and 64 bit userland. */ struct ethtool_cmd { __u32 cmd; __u32 supported; /* Features this interface supports */ __u32 advertising; /* Features this interface advertises */ __u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */ __u8 duplex; /* Duplex, half or full */ __u8 port; /* Which connector port */ __u8 phy_address; __u8 transceiver; /* Which transceiver to use */ __u8 autoneg; /* Enable or disable autonegotiation */ __u32 maxtxpkt; /* Tx pkts before generating tx int */ __u32 maxrxpkt; /* Rx pkts before generating rx int */ __u32 reserved[4]; }; /* wake-on-lan settings */ struct ethtool_wolinfo { __u32 cmd; __u32 supported; __u32 wolopts; __u8 sopass[SOPASS_MAX]; /* SecureOn(tm) password */ }; /* for passing single values */ struct ethtool_value { __u32 cmd; __u32 data; }; static int do_gset(int fd, struct ifreq *ifr) { int err; struct ethtool_cmd ecmd; struct ethtool_wolinfo wolinfo; struct ethtool_value edata; int allfail = 1; fprintf(stdout, "Settings for %s:\n", devname); edata.cmd = ETHTOOL_GMSGLVL; ifr->ifr_data = (caddr_t)&edata; err = ioctl(fd, SIOCETHTOOL, ifr); if (err == 0) { fprintf(stdout, " Current message level: 0x%08x (%d)\n", edata.data, edata.data); allfail = 0; } else if (errno != EOPNOTSUPP) { perror("Cannot get message level"); } edata.cmd = ETHTOOL_GLINK; ifr->ifr_data = (caddr_t)&edata; err = ioctl(fd, SIOCETHTOOL, ifr); if (err == 0) { fprintf(stdout, " Link detected: %s\n", edata.data ? "yes":"no"); allfail = 0; } else if (errno != EOPNOTSUPP) { perror("Cannot get link status"); } if (allfail) { fprintf(stdout, "No data available\n"); return 75; } return 0; } main(int argc, char **argv) { int fd; struct ifreq ifr; if(argc != 2) { printf("usage: %s ethdevice\n", argv[0]); exit(0); } devname = argv[1]; /* Setup our control structures. */ memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, devname); /* Open control socket. */ fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { perror("Cannot get control socket"); return 70; } do_gset(fd, &ifr); }