Exemplo n.º 1
0
/**
 * udev_device_get_devtype:
 * @udev_device: udev device
 *
 * Retrieve the devtype string of the udev device.
 *
 * Returns: the devtype name of the udev device, or #NULL if it can not be determined
 **/
_public_ const char *udev_device_get_devtype(struct udev_device *udev_device)
{
        const char *devtype;
        int r;

        assert_return_errno(udev_device, NULL, EINVAL);

        r = sd_device_get_devtype(udev_device->device, &devtype);
        if (r < 0) {
                errno = -r;
                return NULL;
        }

        return devtype;
}
Exemplo n.º 2
0
static int link_get_type_string(int iftype, sd_device *d, char **ret) {
        const char *t;
        char *p;

        assert(ret);

        if (iftype == ARPHRD_ETHER && d) {
                const char *devtype = NULL, *id = NULL;
                /* WLANs have iftype ARPHRD_ETHER, but we want
                 * to show a more useful type string for
                 * them */

                (void)sd_device_get_devtype(d, &devtype);

                if (streq_ptr(devtype, "wlan"))
                        id = "wlan";
                else if (streq_ptr(devtype, "wwan"))
                        id = "wwan";

                if (id) {
                        p = strdup(id);
                        if (!p)
                                return -ENOMEM;

                        *ret = p;
                        return 1;
                }
        }

        t = arphrd_to_name(iftype);
        if (!t) {
                *ret = NULL;
                return 0;
        }

        p = strdup(t);
        if (!p)
                return -ENOMEM;

        ascii_strlower(p);
        *ret = p;

        return 0;
}