From 7181f929279bea55c8554a86b5cdec9d0c09a7cc Mon Sep 17 00:00:00 2001 From: laforge Date: Mon, 20 Nov 2000 11:43:22 +0000 Subject: huge reorganization for 0.9 - added hashtables everywhere - no more dynamic allocation for each packet - mysql output plugin - more keys in ulogd_BASE - moved libipulog into ulogd directory - introduced autoconf --- libipulog.old/ulog_test.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 libipulog.old/ulog_test.c (limited to 'libipulog.old/ulog_test.c') diff --git a/libipulog.old/ulog_test.c b/libipulog.old/ulog_test.c new file mode 100644 index 0000000..771dab6 --- /dev/null +++ b/libipulog.old/ulog_test.c @@ -0,0 +1,83 @@ +/* ulog_test, $Revision: 1.3 $ + * + * small testing program for libipulog, part of the netfilter ULOG target + * for the linux 2.4 netfilter subsystem. + * + * (C) 2000 by Harald Welte + * + * this code is released under the terms of GNU GPL + * + * $Id: ulog_test.c,v 1.3 2000/09/22 06:57:16 laforge Exp $ + */ + +#include +#include +#include + +#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=%lu 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"); + +} + +int main(int argc, char *argv[]) +{ + struct ipulog_handle *h; + unsigned char* buf; + size_t len; + ulog_packet_msg_t *upkt; + int i; + + if (argc != 4) { + fprintf(stderr, "Usage: %s count group timeout\n", argv[0]); + exit(1); + } + + /* allocate a receive buffer */ + buf = (unsigned char *) malloc(MYBUFSIZ); + + /* create ipulog handle */ + h = ipulog_create_handle(ipulog_group2gmask(atoi(argv[2]))); + if (!h) + { + /* if some error occurrs, print it to stderr */ + ipulog_perror(NULL); + exit(1); + } + + alarm(atoi(argv[3])); + + /* loop receiving packets and handling them over to handle_packet */ + for (i = 0; i < atoi(argv[1]); i++) { + len = ipulog_read(h, buf, BUFSIZ, 1); + if (len < 0) { + ipulog_perror("ulog_test: short read"); + exit(1); + } + upkt = ipulog_get_packet(buf); + printf("%d: ", len); + handle_packet(upkt); + } + + /* just to give it a cleaner look */ + ipulog_destroy_handle(h); + return 0; +} -- cgit v1.2.3