From: Kay Sievers Date: Sat, 5 Mar 2011 05:26:39 +0000 (+0100) Subject: libudev: resolve ifindex in udev_device_new_from_id_filename() X-Git-Tag: 174~242 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e0a2c9a50d799fb623694de2f821f46ec01e2ae;p=systemd libudev: resolve ifindex in udev_device_new_from_id_filename() --- diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c index 8b8507c3..c78cf9b7 100644 --- a/libudev/libudev-device.c +++ b/libudev/libudev-device.c @@ -19,7 +19,11 @@ #include #include #include +#include #include +#include +#include +#include #include "libudev.h" #include "libudev-private.h" @@ -497,6 +501,35 @@ struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id if (sscanf(id, "%c%i:%i", &type, &maj, &min) != 3) return NULL; return udev_device_new_from_devnum(udev, type, makedev(maj, min)); + case 'n': { + int sk; + struct ifreq ifr; + struct udev_device *dev; + int ifindex; + + ifindex = strtoul(&id[1], NULL, 10); + if (ifindex <= 0) + return NULL; + + sk = socket(PF_INET, SOCK_DGRAM, 0); + if (sk < 0) + return NULL; + memset(&ifr, 0x00, sizeof(struct ifreq)); + ifr.ifr_ifindex = ifindex; + if (ioctl(sk, SIOCGIFNAME, &ifr) != 0) { + close(sk); + return NULL; + } + close(sk); + + dev = udev_device_new_from_subsystem_sysname(udev, "net", ifr.ifr_name); + if (dev == NULL) + return NULL; + if (udev_device_get_ifindex(dev) == ifindex) + return dev; + udev_device_unref(dev); + return NULL; + } case '+': util_strscpy(subsys, sizeof(subsys), &id[1]); sysname = strchr(subsys, ':');