1 #include "../src/utils.h"
6 static void change_cb(struct nl_cache *cache, struct nl_object *obj,
9 struct nl_dump_params dp = {
10 .dp_type = NL_DUMP_LINE,
14 if (action == NL_ACT_NEW)
16 else if (action == NL_ACT_DEL)
18 else if (action == NL_ACT_CHANGE)
21 nl_object_dump(obj, &dp);
24 static void sigint(int arg)
29 int main(int argc, char *argv[])
31 struct nl_cache_mngr *mngr;
32 struct nl_cache *lc, *nc, *ac, *rc;
36 signal(SIGINT, sigint);
38 sock = nlt_alloc_socket();
39 err = nl_cache_mngr_alloc(sock, NETLINK_ROUTE, NL_AUTO_PROVIDE, &mngr);
41 fatal(err, "Unable to allocate cache manager: %s",
44 if ((err = nl_cache_mngr_add(mngr, "route/link", &change_cb, &lc)) < 0)
45 fatal(err, "Unable to add cache route/link: %s",
48 if ((err = nl_cache_mngr_add(mngr, "route/neigh", &change_cb, &nc)) < 0)
49 fatal(err, "Unable to add cache route/neigh: %s",
52 if ((err = nl_cache_mngr_add(mngr, "route/addr", &change_cb, &ac)) < 0)
53 fatal(err, "Unable to add cache route/addr: %s",
56 if ((err = nl_cache_mngr_add(mngr, "route/route", &change_cb, &rc)) < 0)
57 fatal(err, "Unable to add cache route/route: %s",
61 int err = nl_cache_mngr_poll(mngr, 5000);
62 if (err < 0 && err != -NLE_INTR)
63 fatal(err, "Polling failed: %s", nl_geterror(err));
67 nl_cache_mngr_free(mngr);