Is there any API(or special file) on Linux that provides an event on the change in link status of an ethernet card without polling ? i.e. when you plug in/out the cable ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can get link up/down events via netlink. You would create a
PF_NETLINKsocket, bind to theRTMGRP_LINKgroup, and wait forRTM_NEWLINK/RTM_DELLINKmessages. Link up events haveIFF_RUNNINGandIFF_LOWER_UPset inifinfomsg.flags, while link down events have both flags cleared (funnily enough, I’m gettingRTM_NEWLINKmessages for both type of events).