8#include <netlink/cli/utils.h> 
    9#include <netlink/netfilter/nfnl.h> 
   11#include <linux/netlink.h> 
   12#include <linux/netfilter/nfnetlink.h> 
   14static void obj_input(
struct nl_object *obj, 
void *arg)
 
   25static int event_input(
struct nl_msg *msg, 
void *arg)
 
   27        if (nl_msg_parse(msg, &obj_input, NULL) < 0)
 
   28                fprintf(stderr, 
"<<EVENT>> Unknown message type\n");
 
   34int main(
int argc, 
char *argv[])
 
   41                enum nfnetlink_groups gr_id;
 
   44                { NFNLGRP_CONNTRACK_NEW, 
"ct-new" },
 
   45                { NFNLGRP_CONNTRACK_UPDATE, 
"ct-update" },
 
   46                { NFNLGRP_CONNTRACK_DESTROY, 
"ct-destroy" },
 
   47                { NFNLGRP_NONE, NULL }
 
   50        sock = nl_cli_alloc_socket();
 
   54        if (argc > 1 && !strcasecmp(argv[1], 
"-h")) {
 
   55                printf(
"Usage: nf-monitor [<groups>]\n");
 
   57                printf(
"Known groups:");
 
   58                for (i = 0; groups[i].gr_id != NFNLGRP_NONE; i++)
 
   59                        printf(
" %s", groups[i].gr_name);
 
   64        nl_cli_connect(sock, NETLINK_NETFILTER);
 
   66        for (idx = 1; argc > idx; idx++) {
 
   67                for (i = 0; groups[i].gr_id != NFNLGRP_NONE; i++) {
 
   68                        if (strcmp(argv[idx], groups[i].gr_name))
 
   71                        err = nl_socket_add_membership(sock, groups[i].gr_id);
 
   74                                             "Unable to add membership: %s",
 
   79                if (groups[i].gr_id == NFNLGRP_NONE)
 
   93                retval = select(fd+1, &rfds, NULL, NULL, NULL);
 
@ NL_STOP
Stop parsing altogether and discard remaining messages.
 
@ NL_CB_VALID
Message is valid.
 
@ NL_CB_CUSTOM
Customized handler specified by the user.
 
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
 
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
 
int nl_recvmsgs_default(struct nl_sock *sk)
Receive a set of message from a netlink socket using handlers in nl_sock.
 
int nl_socket_get_fd(const struct nl_sock *sk)
Return the file descriptor of the backing socket.
 
void nl_socket_disable_seq_check(struct nl_sock *sk)
Disable sequence number checking.
 
int nl_socket_modify_cb(struct nl_sock *sk, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func, void *arg)
Modify the callback handler associated with the socket.
 
@ NL_DUMP_STATS
Dump all attributes including statistics.
 
enum nl_dump_type dp_type
Specifies the type of dump that is requested.