#include <linux/sockios.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define ETHTOOL_GLINK 0x0000000a /* Get link status (ethtool_value) */
typedef enum { IFSTATUS_UP, IFSTATUS_DOWN, IFSTATUS_ERR } interface_status_t;
typedef signed int u32;
/* for passing single values */
struct ethtool_value
{
u32 cmd;
u32 data;
};
interface_status_t interface_detect_beat_ethtool(int fd, char *iface)
{
struct ifreq ifr;
struct ethtool_value edata;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
edata.cmd = ETHTOOL_GLINK;
ifr.ifr_data = (caddr_t) &edata;
if (ioctl(fd, SIOCETHTOOL, &ifr) == -1)
{
perror("ETHTOOL_GLINK failed ");
return IFSTATUS_ERR;
}
return eda