summaryrefslogtreecommitdiffstats
path: root/utils/nfulnl_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/nfulnl_test.c')
-rw-r--r--utils/nfulnl_test.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/utils/nfulnl_test.c b/utils/nfulnl_test.c
index dd3091b..4f29f17 100644
--- a/utils/nfulnl_test.c
+++ b/utils/nfulnl_test.c
@@ -6,33 +6,50 @@
#include <libnetfilter_log/libnetfilter_log.h>
-static int print_pkt(struct nflog_data *ldata)
+static int print_pkt(struct nflog_data *nfad)
{
- struct nfulnl_msg_packet_hdr *ph = nflog_get_msg_packet_hdr(ldata);
- uint32_t mark = nflog_get_nfmark(ldata);
- uint32_t indev = nflog_get_indev(ldata);
- uint32_t outdev = nflog_get_outdev(ldata);
- char *prefix = nflog_get_prefix(ldata);
+ uint32_t outdev, indev, hw_addrlen;
+ struct nfulnl_msg_packet_hdr *ph;
+ struct nfulnl_msg_packet_hw *hw;
+ int payload_len;
char *payload;
- int payload_len = nflog_get_payload(ldata, &payload);
-
+ char *prefix;
+ int i;
+
+ ph = nflog_get_msg_packet_hdr(nfad);
if (ph) {
- printf("hw_protocol=0x%04x hook=%u ",
+ printf("hw_protocol=0x%04x hook=%u ",
ntohs(ph->hw_protocol), ph->hook);
}
- printf("mark=%u ", mark);
+ hw = nflog_get_packet_hw(nfad);
+ if (hw) {
+ hw_addrlen = ntohs(hw->hw_addrlen);
+ printf("hw_addrlen=%d ", hw_addrlen);
+
+ printf("hw_addr=");
+ for (i = 0; i < hw_addrlen - 1; i++)
+ printf("%02x:", hw->hw_addr[i]);
+
+ printf("%02x ", hw->hw_addr[hw_addrlen - 1]);
+ }
+ printf("mark=%u ", nflog_get_nfmark(nfad));
+
+ indev = nflog_get_indev(nfad);
if (indev > 0)
printf("indev=%u ", indev);
+ outdev = nflog_get_outdev(nfad);
if (outdev > 0)
printf("outdev=%u ", outdev);
- if (prefix) {
+ prefix = nflog_get_prefix(nfad);
+ if (prefix)
printf("prefix=\"%s\" ", prefix);
- }
+
+ payload_len = nflog_get_payload(nfad, &payload);
if (payload_len >= 0)
printf("payload_len=%d ", payload_len);
@@ -51,52 +68,52 @@ static int cb(struct nflog_g_handle *gh, struct nfgenmsg *nfmsg,
int main(int argc, char **argv)
{
struct nflog_handle *h;
- struct nflog_g_handle *qh;
- struct nflog_g_handle *qh100;
+ struct nflog_g_handle *gh;
+ struct nflog_g_handle *gh100;
int rv, fd;
char buf[4096];
h = nflog_open();
if (!h) {
- fprintf(stderr, "error during nflog_open()\n");
+ perror("nflog_open");
exit(1);
}
printf("unbinding existing nf_log handler for AF_INET (if any)\n");
if (nflog_unbind_pf(h, AF_INET) < 0) {
- fprintf(stderr, "error nflog_unbind_pf()\n");
+ perror("nflog_unbind_pf");
exit(1);
}
printf("binding nfnetlink_log to AF_INET\n");
if (nflog_bind_pf(h, AF_INET) < 0) {
- fprintf(stderr, "error during nflog_bind_pf()\n");
+ perror("nflog_bind_pf");
exit(1);
}
printf("binding this socket to group 0\n");
- qh = nflog_bind_group(h, 0);
- if (!qh) {
- fprintf(stderr, "no handle for grup 0\n");
+ gh = nflog_bind_group(h, 0);
+ if (!gh) {
+ perror("nflog_bind_group 0");
exit(1);
}
printf("binding this socket to group 100\n");
- qh100 = nflog_bind_group(h, 100);
- if (!qh100) {
- fprintf(stderr, "no handle for group 100\n");
+ gh100 = nflog_bind_group(h, 100);
+ if (!gh100) {
+ perror("nflog_bind_group 100");
exit(1);
}
printf("setting copy_packet mode\n");
- if (nflog_set_mode(qh, NFULNL_COPY_PACKET, 0xffff) < 0) {
- fprintf(stderr, "can't set packet copy mode\n");
+ if (nflog_set_mode(gh, NFULNL_COPY_PACKET, 0xffff) < 0) {
+ perror("nflog_set_mode NFULNL_COPY_PACKET");
exit(1);
}
fd = nflog_fd(h);
printf("registering callback for group 0\n");
- nflog_callback_register(qh, &cb, NULL);
+ nflog_callback_register(gh, &cb, NULL);
printf("going into main loop\n");
while ((rv = recv(fd, buf, sizeof(buf), 0)) && rv >= 0) {
@@ -107,9 +124,9 @@ int main(int argc, char **argv)
}
printf("unbinding from group 100\n");
- nflog_unbind_group(qh100);
+ nflog_unbind_group(gh100);
printf("unbinding from group 0\n");
- nflog_unbind_group(qh);
+ nflog_unbind_group(gh);
#ifdef INSANE
/* norally, applications SHOULD NOT issue this command,