***/
#include <netinet/ether.h>
+#include <net/if.h>
#include "util.h"
#include "macro.h"
_cleanup_rtnl_message_unref_ sd_rtnl_message *message;
const char *mac = "98:fe:94:3f:c6:18", *name = "test";
unsigned int mtu = 1450, mtu_out;
- char *name_out;
+ const char *name_out;
struct ether_addr mac_out;
/* we'd really like to test NEWLINK, but let's not mess with the running kernel */
sd_rtnl_message *m;
sd_rtnl_message *r;
unsigned int mtu = 1500;
- char *str_data;
+ const char *str_data;
uint8_t u8_data;
uint32_t u32_data;
struct ether_addr eth_data;
sd_rtnl_message *r;
struct in_addr in_data;
struct ifa_cacheinfo cache;
- char *label;
+ const char *label;
assert_se(sd_rtnl_message_new_addr(rtnl, &m, RTM_GETADDR, ifindex, AF_INET) >= 0);
assert_se(m);
}
static int link_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
- char *ifname = userdata, *data;
+ char *ifname = userdata;
+ const char *data;
assert_se(rtnl);
assert_se(m);
_cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
uint16_t u16_data;
uint32_t u32_data;
- char *string_data;
+ const char *string_data;
assert_se(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0);
assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
}
+static void test_get_addresses(sd_rtnl *rtnl) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
+ sd_rtnl_message *m;
+
+ assert_se(sd_rtnl_message_new_addr(rtnl, &req, RTM_GETADDR, 0, AF_UNSPEC) >= 0);
+
+ assert_se(sd_rtnl_call(rtnl, req, 0, &reply) >= 0);
+
+ for (m = reply; m; m = sd_rtnl_message_next(m)) {
+ uint16_t type;
+ unsigned char family, scope, flags;
+ int ifindex;
+
+ assert_se(sd_rtnl_message_get_type(m, &type) >= 0);
+ assert_se(type == RTM_NEWADDR);
+
+ assert_se(sd_rtnl_message_addr_get_ifindex(m, &ifindex) >= 0);
+ assert_se(sd_rtnl_message_addr_get_family(m, &family) >= 0);
+ assert_se(sd_rtnl_message_addr_get_scope(m, &scope) >= 0);
+ assert_se(sd_rtnl_message_addr_get_flags(m, &flags) >= 0);
+
+ assert_se(ifindex > 0);
+ assert_se(family == AF_INET || family == AF_INET6);
+
+ log_info("got IPv%u address on ifindex %i", family == AF_INET ? 4: 6, ifindex);
+ }
+}
+
int main(void) {
sd_rtnl *rtnl;
sd_rtnl_message *m;
sd_rtnl_message *r;
- char *string_data;
+ const char *string_data;
int if_loopback;
uint16_t type;
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);