Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
How do I get the link state (whether cable is plugged in or not) of an ethernet interface? Is it enough to query the IFF_RUNNING flag in if_flags field of ifreq structure, via a SIOCGIFFLAGS ioctl, or is something more required.
(BTW, I already tried the ioctl method, with no luck. Below is the code I used.)
int retVal;
struct ifreq ifr;
retVal = ioctl(sockData->sockInt, SIOCGIFFLAGS, &ifr);
if (retVal < 0)
{
debug_printf(DEBUG_NORMAL, "Interface %s not found!\n", ctx->intName);
return FALSE;
}
Thanks Tinkster. Tried it but no dice. Its using the netif_carrier_ok function, which I think cannot be used in userspace. Further on the netif_carrier_ok function tests the flag (or macro) __LINK_STATE_NOCARRIER, from a set of flags contained in net_device structure, which, again, cannot be used from userspace (I think ). Do correct me if I'm wrong.
Perhaps i need to make myself clearer. I have to do this via a C program ONLY, no scripts allowed.
Another thing. I am doing this as part of running xsupplicant (open source Linux version). I notice that the the IFF_RUNNING flag is updated properly each time before I run xsupplicant. However, after I simply run xsupplicant once, the flag is no longer updated. Wierd.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.