1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <libudev.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <unistd.h>
int main (void)
{
struct udev *udev;
struct udev_device *dev;
struct udev_monitor *mon;
// Create the udev object
udev = udev_new();
if (!udev)
{
printf("Can't create udev\n");
exit(1);
}
mon = udev_monitor_new_from_netlink(udev, "udev");
udev_monitor_filter_add_match_subsystem_devtype(mon, "usb", "usb_device");
udev_monitor_enable_receiving(mon);
while (1)
{
dev = udev_monitor_receive_device(mon);
if (dev)
{
printf("Got Device\n");
printf(" VID/PID: %s %s\n", udev_device_get_sysattr_value(dev,"idVendor"), udev_device_get_sysattr_value(dev, "idProduct"));
printf(" Manuf: %s\n Product: %s\n", udev_device_get_sysattr_value(dev,"manufacturer"), udev_device_get_sysattr_value(dev,"product"));
printf(" Serial: %s\n", udev_device_get_sysattr_value(dev, "serial"));
printf(" Node: %s\n", udev_device_get_devnode(dev));
printf(" Subsystem: %s\n", udev_device_get_subsystem(dev));
printf(" Devtype: %s\n", udev_device_get_devtype(dev));
printf(" Action: %s\n", udev_device_get_action(dev));
udev_device_unref(dev);
}
else
{
printf("No Device from receive_device(). An error occured.\n");
}
}
udev_unref(udev);
return 0;
} |
Partager