Detecting when new hardware is plugged in

Hi,
how do I get notifications when hardware (e.g. USB devices) is hotplugged from a C/C++ application? On Linux, I can listen for those events on a socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT) -- there's probably something similar in FreeBSD?

Also, is there a way to get notifications when a network cable is plugged in or out (equivalent to monitoring ifi_flags on a socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE) on Linux)?

Thanks
bero
 
I recommend looking at devd(8) source to see what APIs it uses.

Alternatively, use it as is by editing /etc/devd.conf as needed or reading from /var/run/devd.pipe. See its man page for more information.
 
Back
Top