示例#1
0
int main(void) {
        _cleanup_(manager_freep) Manager *manager = NULL;
        _cleanup_(sd_device_unrefp) sd_device *loopback = NULL;
        int ifindex, r;

        test_setup_logging(LOG_INFO);

        test_deserialize_in_addr();
        test_deserialize_dhcp_routes();
        test_address_equality();
        test_dhcp_hostname_shorten_overlong();

        assert_se(manager_new(&manager) >= 0);

        r = test_load_config(manager);
        if (r == -EPERM)
                return log_tests_skipped("Cannot load configuration");
        assert_se(r == 0);

        assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
        assert_se(loopback);
        assert_se(sd_device_get_ifindex(loopback, &ifindex) >= 0);
        assert_se(ifindex == 1);

        test_network_get(manager, loopback);

        assert_se(manager_rtnl_enumerate_links(manager) >= 0);
}
示例#2
0
int udev_device_get_ifindex(struct udev_device *udev_device) {
        int r, ifindex;

        assert(udev_device);

        r = sd_device_get_ifindex(udev_device->device, &ifindex);
        if (r < 0)
                return r;

        return ifindex;
}