1 /* ulog_test, $Revision: 5293 $
3 * small testing program for libipulog, part of the netfilter ULOG target
4 * for the linux 2.4 netfilter subsystem.
6 * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org>
8 * this code is released under the terms of GNU GPL
10 * $Id: ulog_test.c 5293 2005-03-11 11:47:53Z laforge $
15 #include <libipulog/libipulog.h>
19 /* prints some logging about a single packet */
20 void handle_packet(ulog_packet_msg_t *pkt)
25 printf("Hook=%u Mark=%lu len=%d ",
26 pkt->hook, pkt->mark, pkt->data_len);
27 if (strlen(pkt->prefix))
28 printf("Prefix=%s ", pkt->prefix);
34 for (i = 0; i < pkt->mac_len; i++, p++)
35 printf("%02x%c", *p, i==pkt->mac_len-1 ? ' ':':');
41 int main(int argc, char *argv[])
43 struct ipulog_handle *h;
46 ulog_packet_msg_t *upkt;
50 fprintf(stderr, "Usage: %s count group timeout\n", argv[0]);
54 /* allocate a receive buffer */
55 buf = (unsigned char *) malloc(MYBUFSIZ);
57 /* create ipulog handle */
58 h = ipulog_create_handle(ipulog_group2gmask(atoi(argv[2])),150000);
61 /* if some error occurrs, print it to stderr */
68 /* loop receiving packets and handling them over to handle_packet */
69 for (i = 0; i < atoi(argv[1]); i++) {
70 len = ipulog_read(h, buf, MYBUFSIZ, 1);
72 ipulog_perror("ulog_test: short read");
75 printf("%d bytes received\n", len);
76 while (upkt = ipulog_get_packet(h, buf, len)) {
81 /* just to give it a cleaner look */
82 ipulog_destroy_handle(h);