# Detecting when new hardware is plugged in



## bero (Oct 14, 2009)

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


----------



## aragon (Oct 15, 2009)

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.


----------

