Testing ethernet interface status

Peter Steele psteele at maxiscale.com
Thu Apr 1 18:21:03 UTC 2010


What's the best what to test the status of an Ethernet interface programmatically? We've been using this code similar to this:

struct ifmediareq ifmr;
memset(&ifmr, 0, sizeof(ifmr));
strcpy(ifmr.ifm_name, "nfe0");
ioctl(sockfd, SIOCGIFMEDIA, (caddr_t)&ifmr)

and then checking the value of ifmr.ifm_status & IFM_ACTIVE. We've found that every once in a while this code will return a false positive, indicating that the interface has gone offline when in fact it has not.

So, is there a more reliable call to test if an Ethernet interface has gone offline?


More information about the freebsd-questions mailing list