struct ifreq ifr;
strcpy(ifr.ifr_name, "eth0"); // <== Interface name goes here
if(ioctl(sock,SIOCGIFFLAGS,&ifr) == 0)
if(ifr.ifr_ifru.ifru_flags & IFF_UP)
printf("eth0 is up\n");
printf("eth0 is down\n");
sock is any open socket. You can just...
struct protoent *proto = getprotobyname("TCP");
int sock = socket(PF_INET,SOCK_STREAM,proto->p_proto);
Nice code to look at is part of net-tools in lib/interface.c
> I'm trying to programmatically determine when my Linux box (more
> specifically RedHat 7.3) has been disconnected from the network (ie cable
> I don't want to use command line tools like ifconfig or similar. Is there
> a library I can use to query a state or register for system events? Is
> there a file I can parse?