dect
/
libnl
Archived
13
0
Fork 0

tests: fix test programs to compile again

This commit is contained in:
Thomas Graf 2012-04-21 10:35:20 +02:00
parent 9af5469004
commit e78975aea8
5 changed files with 49 additions and 45 deletions

View File

@ -1,10 +1,12 @@
#include "../src/utils.h"
#include <netlink/netlink.h>
#include <netlink/cache.h>
#include <netlink/cli/utils.h>
#include <signal.h>
static int quit = 0;
static void change_cb(struct nl_cache *cache, struct nl_object *obj,
int action)
int action, void *data)
{
struct nl_dump_params dp = {
.dp_type = NL_DUMP_LINE,
@ -35,32 +37,32 @@ int main(int argc, char *argv[])
signal(SIGINT, sigint);
sock = nlt_alloc_socket();
sock = nl_cli_alloc_socket();
err = nl_cache_mngr_alloc(sock, NETLINK_ROUTE, NL_AUTO_PROVIDE, &mngr);
if (err < 0)
fatal(err, "Unable to allocate cache manager: %s",
nl_geterror(err));
nl_cli_fatal(err, "Unable to allocate cache manager: %s",
nl_geterror(err));
if ((err = nl_cache_mngr_add(mngr, "route/link", &change_cb, &lc)) < 0)
fatal(err, "Unable to add cache route/link: %s",
nl_geterror(err));
if ((err = nl_cache_mngr_add(mngr, "route/link", &change_cb, NULL, &lc)) < 0)
nl_cli_fatal(err, "Unable to add cache route/link: %s",
nl_geterror(err));
if ((err = nl_cache_mngr_add(mngr, "route/neigh", &change_cb, &nc)) < 0)
fatal(err, "Unable to add cache route/neigh: %s",
nl_geterror(err));
if ((err = nl_cache_mngr_add(mngr, "route/neigh", &change_cb, NULL, &nc)) < 0)
nl_cli_fatal(err, "Unable to add cache route/neigh: %s",
nl_geterror(err));
if ((err = nl_cache_mngr_add(mngr, "route/addr", &change_cb, &ac)) < 0)
fatal(err, "Unable to add cache route/addr: %s",
nl_geterror(err));
if ((err = nl_cache_mngr_add(mngr, "route/addr", &change_cb, NULL, &ac)) < 0)
nl_cli_fatal(err, "Unable to add cache route/addr: %s",
nl_geterror(err));
if ((err = nl_cache_mngr_add(mngr, "route/route", &change_cb, &rc)) < 0)
fatal(err, "Unable to add cache route/route: %s",
nl_geterror(err));
if ((err = nl_cache_mngr_add(mngr, "route/route", &change_cb, NULL, &rc)) < 0)
nl_cli_fatal(err, "Unable to add cache route/route: %s",
nl_geterror(err));
while (!quit) {
int err = nl_cache_mngr_poll(mngr, 5000);
if (err < 0 && err != -NLE_INTR)
fatal(err, "Polling failed: %s", nl_geterror(err));
nl_cli_fatal(err, "Polling failed: %s", nl_geterror(err));
}

View File

@ -16,7 +16,7 @@ int main(int argc, char *argv[])
link = rtnl_link_alloc();
rtnl_link_set_name(link, "my_bond");
if ((err = rtnl_link_set_info_type(link, "bond")) < 0) {
if ((err = rtnl_link_set_type(link, "bond")) < 0) {
nl_perror(err, "Unable to set link info type");
return err;
}

View File

@ -1,4 +1,4 @@
#include "../src/utils.h"
#include <netlink/cli/utils.h>
int main(int argc, char *argv[])
{
@ -7,26 +7,26 @@ int main(int argc, char *argv[])
void *hdr;
int err;
sock = nlt_alloc_socket();
nlt_connect(sock, NETLINK_GENERIC);
sock = nl_cli_alloc_socket();
nl_cli_connect(sock, NETLINK_GENERIC);
msg = nlmsg_alloc();
if (msg == NULL)
fatal(NLE_NOMEM, "Unable to allocate netlink message");
nl_cli_fatal(NLE_NOMEM, "Unable to allocate netlink message");
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, GENL_ID_CTRL,
0, 0, CTRL_CMD_GETFAMILY, 1);
if (hdr == NULL)
fatal(ENOMEM, "Unable to write genl header");
nl_cli_fatal(ENOMEM, "Unable to write genl header");
if ((err = nla_put_u32(msg, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL)) < 0)
fatal(err, "Unable to add attribute: %s", nl_geterror(err));
nl_cli_fatal(err, "Unable to add attribute: %s", nl_geterror(err));
if ((err = nl_send_auto_complete(sock, msg)) < 0)
fatal(err, "Unable to send message: %s", nl_geterror(err));
nl_cli_fatal(err, "Unable to send message: %s", nl_geterror(err));
if ((err = nl_recvmsgs_default(sock)) < 0)
fatal(err, "Unable to receive message: %s", nl_geterror(err));
nl_cli_fatal(err, "Unable to receive message: %s", nl_geterror(err));
nlmsg_free(msg);
nl_close(sock);

View File

@ -1,13 +1,13 @@
#include "../src/utils.h"
#include <netlink/cli/utils.h>
static void change_cb(struct nl_cache *cache, struct nl_object *obj,
int action)
int action, void *data)
{
struct nfnl_ct *ct = (struct nfnl_ct *) obj;
static struct nl_addr *hack = NULL;
if (!hack)
hack = nl_addr_parse("194.88.212.233", AF_INET);
nl_addr_parse("194.88.212.233", AF_INET, &hack);
if (!nl_addr_cmp(hack, nfnl_ct_get_src(ct, 1)) ||
!nl_addr_cmp(hack, nfnl_ct_get_dst(ct, 1))) {
@ -26,25 +26,26 @@ int main(int argc, char *argv[])
struct nl_cache_mngr *mngr;
struct nl_sock *sock;
struct nl_cache *ct;
int err;
sock = nlt_socket_alloc();
sock = nl_cli_alloc_socket();
mngr = nl_cache_mngr_alloc(sock, NETLINK_NETFILTER, NL_AUTO_PROVIDE);
if (!mngr) {
nl_perror("nl_cache_mngr_alloc");
err = nl_cache_mngr_alloc(sock, NETLINK_NETFILTER, NL_AUTO_PROVIDE, &mngr);
if (err < 0) {
nl_perror(err, "nl_cache_mngr_alloc");
return -1;
}
ct = nl_cache_mngr_add(mngr, "netfilter/ct", &change_cb);
if (ct == NULL) {
nl_perror("nl_cache_mngr_add(netfilter/ct)");
err = nl_cache_mngr_add(mngr, "netfilter/ct", &change_cb, NULL, &ct);
if (err < 0) {
nl_perror(err, "nl_cache_mngr_add(netfilter/ct)");
return -1;
}
for (;;) {
int err = nl_cache_mngr_poll(mngr, 5000);
if (err < 0) {
nl_perror("nl_cache_mngr_poll()");
nl_perror(err, "nl_cache_mngr_poll()");
return -1;
}

View File

@ -1,23 +1,24 @@
#include "../src/utils.h"
#include <netlink/netlink.h>
#include <errno.h>
int main(int argc, char *argv[])
{
struct nl_sock *h[1025];
int i;
h[0] = nl_handle_alloc();
h[0] = nl_socket_alloc();
printf("Created handle with port 0x%x\n",
nl_socket_get_local_port(h[0]));
nl_handle_destroy(h[0]);
h[0] = nl_handle_alloc();
nl_socket_free(h[0]);
h[0] = nl_socket_alloc();
printf("Created handle with port 0x%x\n",
nl_socket_get_local_port(h[0]));
nl_handle_destroy(h[0]);
nl_socket_free(h[0]);
for (i = 0; i < 1025; i++) {
h[i] = nl_handle_alloc();
h[i] = nl_socket_alloc();
if (h[i] == NULL)
nl_perror("Unable to allocate socket");
nl_perror(ENOMEM, "Unable to allocate socket");
else
printf("Created handle with port 0x%x\n",
nl_socket_get_local_port(h[i]));