14 #include <netlink/cli/utils.h>
15 #include <netlink/netfilter/nfnl.h>
17 static void obj_input(
struct nl_object *obj,
void *arg)
28 static int event_input(
struct nl_msg *msg,
void *arg)
30 if (nl_msg_parse(msg, &obj_input, NULL) < 0)
31 fprintf(stderr,
"<<EVENT>> Unknown message type\n");
37 int main(
int argc,
char *argv[])
44 enum nfnetlink_groups gr_id;
47 { NFNLGRP_CONNTRACK_NEW,
"ct-new" },
48 { NFNLGRP_CONNTRACK_UPDATE,
"ct-update" },
49 { NFNLGRP_CONNTRACK_DESTROY,
"ct-destroy" },
50 { NFNLGRP_NONE, NULL }
53 sock = nl_cli_alloc_socket();
57 if (argc > 1 && !strcasecmp(argv[1],
"-h")) {
58 printf(
"Usage: nf-monitor [<groups>]\n");
60 printf(
"Known groups:");
61 for (i = 0; groups[i].gr_id != NFNLGRP_NONE; i++)
62 printf(
" %s", groups[i].gr_name);
67 nl_cli_connect(sock, NETLINK_NETFILTER);
69 for (idx = 1; argc > idx; idx++) {
70 for (i = 0; groups[i].gr_id != NFNLGRP_NONE; i++) {
71 if (strcmp(argv[idx], groups[i].gr_name))
74 err = nl_socket_add_membership(sock, groups[i].gr_id);
77 "Unable to add membership: %s",
82 if (groups[i].gr_id == NFNLGRP_NONE)
96 retval = select(fd+1, &rfds, NULL, NULL, NULL);
Customized handler specified by the user.
int nl_socket_get_fd(const struct nl_sock *sk)
Return the file descriptor of the backing socket.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
Stop parsing altogether and discard remaining messages.
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.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
void nl_socket_disable_seq_check(struct nl_sock *sk)
Disable sequence number checking.
int nl_recvmsgs_default(struct nl_sock *sk)
Receive a set of message from a netlink socket using handlers in nl_sock.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Dump all attributes including statistics.