14 #include <netlink/cli/utils.h> 15 #include <netlink/netfilter/nfnl.h> 17 #include <linux/netlink.h> 18 #include <linux/netfilter/nfnetlink.h> 20 static void obj_input(
struct nl_object *obj,
void *arg)
31 static int event_input(
struct nl_msg *msg,
void *arg)
33 if (nl_msg_parse(msg, &obj_input, NULL) < 0)
34 fprintf(stderr,
"<<EVENT>> Unknown message type\n");
40 int main(
int argc,
char *argv[])
47 enum nfnetlink_groups gr_id;
50 { NFNLGRP_CONNTRACK_NEW,
"ct-new" },
51 { NFNLGRP_CONNTRACK_UPDATE,
"ct-update" },
52 { NFNLGRP_CONNTRACK_DESTROY,
"ct-destroy" },
53 { NFNLGRP_NONE, NULL }
56 sock = nl_cli_alloc_socket();
60 if (argc > 1 && !strcasecmp(argv[1],
"-h")) {
61 printf(
"Usage: nf-monitor [<groups>]\n");
63 printf(
"Known groups:");
64 for (i = 0; groups[i].gr_id != NFNLGRP_NONE; i++)
65 printf(
" %s", groups[i].gr_name);
70 nl_cli_connect(sock, NETLINK_NETFILTER);
72 for (idx = 1; argc > idx; idx++) {
73 for (i = 0; groups[i].gr_id != NFNLGRP_NONE; i++) {
74 if (strcmp(argv[idx], groups[i].gr_name))
77 err = nl_socket_add_membership(sock, groups[i].gr_id);
80 "Unable to add membership: %s",
85 if (groups[i].gr_id == NFNLGRP_NONE)
99 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.