00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <string.h>
00016 #include <libnetfilter_log/libipulog.h>
00017
00018 #define MYBUFSIZ 2048
00019
00020
00021 void handle_packet(ulog_packet_msg_t *pkt)
00022 {
00023 unsigned char *p;
00024 int i;
00025
00026 printf("Hook=%u Mark=%lu len=%d ",
00027 pkt->hook, pkt->mark, pkt->data_len);
00028 if (strlen(pkt->prefix))
00029 printf("Prefix=%s ", pkt->prefix);
00030
00031 if (pkt->mac_len)
00032 {
00033 printf("mac=");
00034 p = pkt->mac;
00035 for (i = 0; i < pkt->mac_len; i++, p++)
00036 printf("%02x%c", *p, i==pkt->mac_len-1 ? ' ':':');
00037 }
00038 printf("\n");
00039
00040 }
00041
00042 int main(int argc, char *argv[])
00043 {
00044 struct ipulog_handle *h;
00045 unsigned char* buf;
00046 int len;
00047 ulog_packet_msg_t *upkt;
00048 int i;
00049
00050 if (argc != 4) {
00051 fprintf(stderr, "Usage: %s count group timeout\n", argv[0]);
00052 exit(2);
00053 }
00054
00055
00056 buf = (unsigned char *) malloc(MYBUFSIZ);
00057 if (!buf)
00058 exit(1);
00059
00060
00061 h = ipulog_create_handle(ipulog_group2gmask(atoi(argv[2])), 65535);
00062 if (!h)
00063 {
00064
00065 ipulog_perror(NULL);
00066 exit(1);
00067 }
00068
00069 alarm(atoi(argv[3]));
00070
00071
00072 for (i = 0; i < atoi(argv[1]); i++) {
00073 len = ipulog_read(h, buf, MYBUFSIZ, 1);
00074 if (len <= 0) {
00075 ipulog_perror("ulog_test: short read");
00076 exit(1);
00077 }
00078 printf("%d bytes received\n", len);
00079 while (upkt = ipulog_get_packet(h, buf, len)) {
00080 handle_packet(upkt);
00081 }
00082 }
00083
00084
00085 ipulog_destroy_handle(h);
00086 return 0;
00087 }