diff options
Diffstat (limited to '_log/utils')
-rw-r--r-- | _log/utils/Makefile.am | 15 | ||||
-rw-r--r-- | _log/utils/nfulnl_test.c | 155 | ||||
-rw-r--r-- | _log/utils/ulog_test.c | 87 |
3 files changed, 0 insertions, 257 deletions
diff --git a/_log/utils/Makefile.am b/_log/utils/Makefile.am deleted file mode 100644 index a2c2f2e..0000000 --- a/_log/utils/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -INCLUDES = $(all_includes) -I$(top_srcdir)/include -I${KERNELDIR} - -bin_PROGRAMS = nfulnl_test ulog_test - -nfulnl_test_SOURCES = nfulnl_test.c -nfulnl_test_LDADD = ../src/libnfnetlink_log.la -nfulnl_test_LDFLAGS = -dynamic -#nfulnl_test_LDFLAGS = $(all_libraries) -lnfnetlink_log - -ulog_test_SOURCES = ulog_test.c -ulog_test_LDADD = ../src/libnfnetlink_log_libipulog.la ../src/libnfnetlink_log.la -ulog_test_LDFLAGS = -dynamic -#ulog_test_LDFLAGS = $(all_libraries) -lnfnetlink_log_libipulog -lnfnetlink_log - - diff --git a/_log/utils/nfulnl_test.c b/_log/utils/nfulnl_test.c deleted file mode 100644 index a6d648e..0000000 --- a/_log/utils/nfulnl_test.c +++ /dev/null @@ -1,155 +0,0 @@ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <netinet/in.h> - -#include <libnfnetlink_log/libnfnetlink_log.h> - -static int print_pkt(struct nfattr *tb[]) -{ - if (tb[NFULA_PACKET_HDR-1]) { - struct nfulnl_msg_packet_hdr *ph = - NFA_DATA(tb[NFULA_PACKET_HDR-1]); - printf("hw_protocol=0x%04x hook=%u ", - ntohs(ph->hw_protocol), ph->hook); - } - - if (tb[NFULA_MARK-1]) { - u_int32_t mark = - ntohl(*(u_int32_t *)NFA_DATA(tb[NFULA_MARK-1])); - printf("mark=%u ", mark); - } - - if (tb[NFULA_IFINDEX_INDEV-1]) { - u_int32_t ifi = ntohl(*(u_int32_t *)NFA_DATA(tb[NFULA_IFINDEX_INDEV-1])); - printf("indev=%u ", ifi); - } - if (tb[NFULA_IFINDEX_OUTDEV-1]) { - u_int32_t ifi = ntohl(*(u_int32_t *)NFA_DATA(tb[NFULA_IFINDEX_OUTDEV-1])); - printf("outdev=%u ", ifi); - } -#if 0 - if (tb[NFULA_IFINDEX_PHYSINDEV-1]) { - u_int32_t ifi = ntohl(*(u_int32_t *)NFA_DATA(tb[NFULA_IFINDEX_PHYSINDEV-1])); - printf("physindev=%u ", ifi); - } - if (tb[NFULA_IFINDEX_PHYSOUTDEV-1]) { - u_int32_t ifi = ntohl(*(u_int32_t *)NFA_DATA(tb[NFULA_IFINDEX_PHYSOUTDEV-1])); - printf("physoutdev=%u ", ifi); - } -#endif - if (tb[NFULA_PREFIX-1]) { - char *prefix = NFA_DATA(tb[NFULA_PREFIX-1]); - printf("prefix=\"%s\" ", prefix); - } - if (tb[NFULA_PAYLOAD-1]) { - printf("payload_len=%d ", NFA_PAYLOAD(tb[NFULA_PAYLOAD-1])); - } - - fputc('\n', stdout); - return 0; -} - -static int cb(struct nfulnl_g_handle *gh, struct nfgenmsg *nfmsg, - struct nfattr *nfa[], void *data) -{ - print_pkt(nfa); -} - - -int main(int argc, char **argv) -{ - struct nfulnl_handle *h; - struct nfulnl_g_handle *qh; - struct nfulnl_g_handle *qh100; - struct nfnl_handle *nh; - int rv, fd; - char buf[4096]; - - h = nfulnl_open(); - if (!h) { - fprintf(stderr, "error during nfulnl_open()\n"); - exit(1); - } - - printf("unbinding existing nf_log handler for AF_INET (if any)\n"); - if (nfulnl_unbind_pf(h, AF_INET) < 0) { - fprintf(stderr, "error nfulnl_unbind_pf()\n"); - exit(1); - } - - printf("binding nfnetlink_log to AF_INET\n"); - if (nfulnl_bind_pf(h, AF_INET) < 0) { - fprintf(stderr, "error during nfulnl_bind_pf()\n"); - exit(1); - } - printf("binding this socket to group 0\n"); - qh = nfulnl_bind_group(h, 0); - if (!qh) { - fprintf(stderr, "no handle for grup 0\n"); - exit(1); - } - - printf("binding this socket to group 100\n"); - qh100 = nfulnl_bind_group(h, 100); - if (!qh100) { - fprintf(stderr, "no handle for group 100\n"); - exit(1); - } - - printf("setting copy_packet mode\n"); - if (nfulnl_set_mode(qh, NFULNL_COPY_PACKET, 0xffff) < 0) { - fprintf(stderr, "can't set packet copy mode\n"); - exit(1); - } - - nh = nfulnl_nfnlh(h); - fd = nfnl_fd(nh); - - printf("registering callback for group 0\n"); - nfulnl_callback_register(qh, &cb, NULL); - - printf("going into main loop\n"); - while ((rv = recv(fd, buf, sizeof(buf), 0)) && rv >= 0) { - struct nlmsghdr *nlh; - printf("pkt received (len=%u)\n", rv); - -#if 0 - for (nlh = nfnl_get_msg_first(nh, buf, rv); - nlh; nlh = nfnl_get_msg_next(nh, buf, rv)) { - struct nfattr *tb[NFULA_MAX]; - struct nfgenmsg *nfmsg; - - printf("msg received: "); - nfnl_parse_hdr(nh, nlh, &nfmsg); - rv = nfnl_parse_attr(tb, NFULA_MAX, NFM_NFA(NLMSG_DATA(nlh)), nlh->nlmsg_len-NLMSG_ALIGN(sizeof(struct nfgenmsg))); - if (rv < 0) { - printf("error during parse: %d\n", rv); - break; - } - print_pkt(tb); - } -#else - /* handle messages in just-received packet */ - nfulnl_handle_packet(h, buf, rv); -#endif - } - - printf("unbinding from group 100\n"); - nfulnl_unbind_group(qh100); - printf("unbinding from group 0\n"); - nfulnl_unbind_group(qh); - -#ifdef INSANE - /* norally, applications SHOULD NOT issue this command, - * since it detaches other programs/sockets from AF_INET, too ! */ - printf("unbinding from AF_INET\n"); - nfulnl_unbind_pf(h, AF_INET); -#endif - - printf("closing handle\n"); - nfulnl_close(h); - - exit(0); -} diff --git a/_log/utils/ulog_test.c b/_log/utils/ulog_test.c deleted file mode 100644 index f8515d3..0000000 --- a/_log/utils/ulog_test.c +++ /dev/null @@ -1,87 +0,0 @@ -/* ulog_test, $Revision: 1.4 $ - * - * small testing program for libipulog, part of the netfilter ULOG target - * for the linux 2.4 netfilter subsystem. - * - * (C) 2000 by Harald Welte <laforge@gnumonks.org> - * - * this code is released under the terms of GNU GPL - * - * $Id: ulog_test.c 286 2002-06-13 12:56:53Z laforge $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <libnfnetlink_log/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=%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; - int len; - ulog_packet_msg_t *upkt; - int i; - - if (argc != 4) { - fprintf(stderr, "Usage: %s count group timeout\n", argv[0]); - exit(2); - } - - /* allocate a receive buffer */ - buf = (unsigned char *) malloc(MYBUFSIZ); - if (!buf) - exit(1); - - /* create ipulog handle */ - h = ipulog_create_handle(ipulog_group2gmask(atoi(argv[2])), 65535); - 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, MYBUFSIZ, 1); - if (len <= 0) { - ipulog_perror("ulog_test: short read"); - exit(1); - } - printf("%d bytes received\n", len); - while (upkt = ipulog_get_packet(h, buf, len)) { - handle_packet(upkt); - } - } - - /* just to give it a cleaner look */ - ipulog_destroy_handle(h); - return 0; -} |