int main(void) { sd_rtnl *rtnl; sd_rtnl_message *m; sd_rtnl_message *r; char *string_data; int if_loopback; uint16_t type; test_match(); test_multiple(); test_route(); test_container(); assert_se(sd_rtnl_open(&rtnl, 0) >= 0); assert_se(rtnl); if_loopback = (int) if_nametoindex("lo"); assert_se(if_loopback > 0); test_async(if_loopback); test_pipe(if_loopback); test_event_loop(if_loopback); test_link_configure(rtnl, if_loopback); test_get_addresses(rtnl); assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, if_loopback) >= 0); assert_se(m); assert_se(sd_rtnl_message_get_type(m, &type) >= 0); assert_se(type == RTM_GETLINK); assert_se(sd_rtnl_message_read_string(m, IFLA_IFNAME, &string_data) == -EPERM); assert_se(sd_rtnl_call(rtnl, m, 0, &r) == 1); assert_se(sd_rtnl_message_get_type(r, &type) >= 0); assert_se(type == RTM_NEWLINK); assert_se((r = sd_rtnl_message_unref(r)) == NULL); assert_se(sd_rtnl_call(rtnl, m, -1, &r) == -EPERM); assert_se((m = sd_rtnl_message_unref(m)) == NULL); assert_se((r = sd_rtnl_message_unref(r)) == NULL); test_link_get(rtnl, if_loopback); test_address_get(rtnl, if_loopback); assert_se(sd_rtnl_flush(rtnl) >= 0); assert_se((m = sd_rtnl_message_unref(m)) == NULL); assert_se((r = sd_rtnl_message_unref(r)) == NULL); assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL); return EXIT_SUCCESS; }
int main(void) { sd_rtnl *rtnl; sd_rtnl_message *m; sd_rtnl_message *r; void *data; int if_loopback; uint16_t type; unsigned int mtu = 0; unsigned int *mtu_reply; test_multiple(); test_route(); test_container(); assert(sd_rtnl_open(0, &rtnl) >= 0); assert(rtnl); if_loopback = (int) if_nametoindex("lo"); assert(if_loopback > 0); test_async(if_loopback); test_pipe(if_loopback); test_event_loop(if_loopback); test_link_configure(rtnl, if_loopback); assert(sd_rtnl_message_link_new(RTM_GETLINK, if_loopback, 0, 0, &m) >= 0); assert(m); assert(sd_rtnl_message_get_type(m, &type) >= 0); assert(type == RTM_GETLINK); assert(sd_rtnl_message_read(m, &type, &data) == 0); assert(sd_rtnl_call(rtnl, m, 0, &r) == 1); assert(sd_rtnl_message_get_type(r, &type) >= 0); assert(type == RTM_NEWLINK); assert(sd_rtnl_message_read(m, &type, &data) == 0); assert((r = sd_rtnl_message_unref(r)) == NULL); assert(sd_rtnl_call(rtnl, m, -1, &r) == -EPERM); assert((m = sd_rtnl_message_unref(m)) == NULL); assert((r = sd_rtnl_message_unref(r)) == NULL); assert(sd_rtnl_message_link_new(RTM_GETLINK, if_loopback, 0, 0, &m) >= 0); assert(m); assert(sd_rtnl_message_append(m, IFLA_MTU, &mtu) >= 0); assert(sd_rtnl_message_read(m, &type, (void **) &mtu_reply) == 1); assert(type == IFLA_MTU); assert(*mtu_reply == 0); assert(sd_rtnl_message_read(m, &type, &data) == 0); assert(sd_rtnl_call(rtnl, m, -1, &r) == 1); while (sd_rtnl_message_read(r, &type, &data) > 0) { switch (type) { // case IFLA_MTU: // assert(*(unsigned int *) data == 65536); // break; // case IFLA_QDISC: // assert(streq((char *) data, "noqueue")); // break; case IFLA_IFNAME: assert(streq((char *) data, "lo")); break; } } assert(sd_rtnl_flush(rtnl) >= 0); assert((m = sd_rtnl_message_unref(m)) == NULL); assert((r = sd_rtnl_message_unref(r)) == NULL); assert((rtnl = sd_rtnl_unref(rtnl)) == NULL); return EXIT_SUCCESS; }