third_party_libnl/tests/test-cache-mngr.c
Thomas Haller 45cbfb9d11 include: don't include kernel headers in public libnl3 headers
It would be desirable not to include kernel headers in our public
libnl3 headers. As a test, remove all those includes, and fix
compilation by explicitly including the kernel headers where needed.
In some cases, that requires forward declaration for kernel
structures, as we use them as part of our own headers.

Realistically, we cannot drop those includes as it probalby breaks
compilation for users that expect to get a certain kernel header
when including a libnl3 header. So, this will not be done and the
includes will be restored in the next commit.

Do this step to show how it would be and to verify that we could
build with such a change. The reason not to do this is backward
compatibility (at compile-time).
2017-03-02 01:33:25 +01:00

69 lines
1.3 KiB
C

#include <netlink/netlink.h>
#include <netlink/cache.h>
#include <netlink/cli/utils.h>
#include <signal.h>
#include <netlink-private/cache-api.h>
#include <linux/netlink.h>
static int quit = 0;
static struct nl_dump_params dp = {
.dp_type = NL_DUMP_LINE,
};
static void change_cb(struct nl_cache *cache, struct nl_object *obj,
int action, void *data)
{
if (action == NL_ACT_NEW)
printf("NEW ");
else if (action == NL_ACT_DEL)
printf("DEL ");
else if (action == NL_ACT_CHANGE)
printf("CHANGE ");
nl_object_dump(obj, &dp);
}
static void sigint(int arg)
{
quit = 1;
}
int main(int argc, char *argv[])
{
struct nl_cache_mngr *mngr;
struct nl_cache *cache;
int err, i;
dp.dp_fd = stdout;
signal(SIGINT, sigint);
err = nl_cache_mngr_alloc(NULL, NETLINK_ROUTE, NL_AUTO_PROVIDE, &mngr);
if (err < 0)
nl_cli_fatal(err, "Unable to allocate cache manager: %s",
nl_geterror(err));
for (i = 1; i < argc; i++) {
err = nl_cache_mngr_add(mngr, argv[i], &change_cb, NULL, &cache);
if (err < 0)
nl_cli_fatal(err, "Unable to add cache %s: %s",
argv[i], nl_geterror(err));
}
while (!quit) {
int err = nl_cache_mngr_poll(mngr, 1000);
if (err < 0 && err != -NLE_INTR)
nl_cli_fatal(err, "Polling failed: %s", nl_geterror(err));
nl_cache_mngr_info(mngr, &dp);
}
nl_cache_mngr_free(mngr);
return 0;
}