fabmilo
fabmilo

Reputation: 48330

How to get notified by the Linux kernel if a new interface has been attached?

I want to be able to detect when a new external device is connected to the linux system and upon that send a notification message to a running process.

I was wondering if there is any other solution than periodically scan for /dev/ and detect if anything has changed.

Upvotes: 2

Views: 869

Answers (1)

artless-noise-bye-due2AI
artless-noise-bye-due2AI

Reputation: 22395

While you can use udev, the underlying mechanism is netlink. Interfaces themselves are not normally in /dev, but do show up under /sys/class/net as sub-directories. However, the hotplug.txt gives a good start to inspecting kernel events. Run the sample code and examine the netlink data when an interface is connected. The text is ASCII that any user space application can parse and use.

Upvotes: 3

Related Questions