/* * This code is GPL. */ #include #include #include #include #define BUFSIZE 2048 static void die (struct ipq_handle *h) { ipq_perror ("DIED !"); ipq_destroy_handle (h); exit (1); } void dump (char *buff, int length) { int i, k, l; k = 0; l = 0; for (i = 0; i < length; i++) { printf ("%02x", 255 & buff[i]); if (k == 3) { if (l == 15) { printf ("\n"); l = 0; } else { printf (" "); l++; } k = 0; } else { k++; l++; } } printf ("\n"); if (l != 0) { printf ("\n"); } } int main (int argc, char **argv) { int status; unsigned char buf[BUFSIZE]; struct ipq_handle *h; int i, k, l; h = ipq_create_handle (0, PF_INET6); if (h == NULL) { fprintf (stderr, "Nach ipq_create_handle\n"); ipq_perror("ipq_create_handle"); die (h); } status = ipq_set_mode (h, IPQ_COPY_PACKET, BUFSIZE); if (status < 0) { fprintf (stderr, "Nach ipq_set_mode\n"); ipq_perror("ipq_set_mode"); die (h); } do { status = ipq_read (h, buf, BUFSIZE, 0); if (status < 0) { fprintf (stderr, "Nach ipq_read\n"); ipq_perror("ipq_read"); die (h); } switch (ipq_message_type (buf)) { case NLMSG_ERROR: fprintf (stderr, "Received error message %d\n", ipq_get_msgerr (buf)); break; case IPQM_PACKET: { time_t t = time(NULL); char timestr[100]; struct tm *zeit; zeit = localtime(&t); strftime(timestr, sizeof(timestr), "[%H:%M:%S]\0", zeit); printf("%s:\n", timestr); ipq_packet_msg_t *m = ipq_get_packet (buf); /* * Processing the packet */ dump (&(m->payload[0]), m->data_len); status = ipq_set_verdict (h, m->packet_id, NF_ACCEPT, 0, NULL); if (status < 0) die (h); break; } default: fprintf (stderr, "Unknown message type!\n"); break; } } while (1); ipq_destroy_handle (h); return 0; }