summaryrefslogtreecommitdiffstats
path: root/ulogd/libipulog/ulog_test.c
diff options
context:
space:
mode:
authorlaforge <laforge>2000-07-30 19:33:09 +0000
committerlaforge <laforge>2000-07-30 19:33:09 +0000
commit5c6ad9785fa043bd5337dd8088f795f89fbcd931 (patch)
treebda8bcd6116cf857201b70b50d61080f592fd291 /ulogd/libipulog/ulog_test.c
Initial revision
Diffstat (limited to 'ulogd/libipulog/ulog_test.c')
-rw-r--r--ulogd/libipulog/ulog_test.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/ulogd/libipulog/ulog_test.c b/ulogd/libipulog/ulog_test.c
new file mode 100644
index 0000000..7fa6504
--- /dev/null
+++ b/ulogd/libipulog/ulog_test.c
@@ -0,0 +1,72 @@
+/* ulog_test, Version $Revision$
+ *
+ * small testing program for libipulog, part of the netfilter ULOG target
+ * for the linux 2.4 netfilter subsystem.
+ *
+ * (C) 2000 by Harald Welte <laforge@sunbeam.franken.de>
+ *
+ * this code is released under the terms of GNU GPL
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <libipulog/libipulog.h>
+
+#define MYBUFSIZ 2048
+
+/* prints some logging about a single packet */
+void handle_packet(ulog_packet_msg_t *pkt)
+{
+ unsigned char *p;
+ int i;
+
+ printf("Hook=%u Mark=%u len=%d ", pkt->hook, pkt->mark, pkt->data_len);
+ if (strlen(pkt->prefix))
+ printf("Prefix=%s ", pkt->prefix);
+
+ if (pkt->mac_len)
+ {
+ printf("mac=");
+ p = pkt->mac;
+ for (i = 0; i < pkt->mac_len; i++, p++)
+ printf("%02x%c", *p, i==pkt->mac_len-1 ? ' ':':');
+ }
+ printf("\n");
+
+}
+
+main()
+{
+ struct ipulog_handle *h;
+ unsigned char* buf;
+ size_t len;
+ ulog_packet_msg_t *upkt;
+
+ /* allocate a receive buffer */
+ buf = (unsigned char *) malloc(MYBUFSIZ);
+
+ /* create ipulog handle */
+ h = ipulog_create_handle(ipulog_group2gmask(32));
+ if (!h)
+ {
+ /* if some error occurrs, print it to stderr */
+ ipulog_perror(NULL);
+ exit(1);
+ }
+
+ /* endless loop receiving packets and handling them over to
+ * handle_packet */
+ while(1)
+ {
+ len = ipulog_read(h, buf, BUFSIZ, 1);
+ upkt = ipulog_get_packet(buf);
+ printf("got %d bytes\n", len);
+ handle_packet(upkt);
+ }
+
+ /* just to give it a cleaner look */
+ ipulog_destroy_handle(h);
+
+}