+/* returns packet id */
+static u_int32_t print_pkt (struct nfattr *tb[])
+{
+ int id = 0;
+
+ if (tb[NFQA_PACKET_HDR-1]) {
+ struct nfqnl_msg_packet_hdr *ph =
+ NFA_DATA(tb[NFQA_PACKET_HDR-1]);
+ id = ntohl(ph->packet_id);
+ printf("hw_protocol=0x%04x hook=%u id=%u ",
+ ntohs(ph->hw_protocol), ph->hook, id);
+ }
+
+ if (tb[NFQA_MARK-1]) {
+ u_int32_t mark =
+ ntohl(*(u_int32_t *)NFA_DATA(tb[NFQA_MARK-1]));
+ printf("mark=%u ", mark);
+ }
+
+ if (tb[NFQA_IFINDEX_INDEV-1]) {
+ u_int32_t ifi =
+ ntohl(*(u_int32_t *)NFA_DATA(tb[NFQA_IFINDEX_INDEV-1]));
+ printf("indev=%u ", ifi);
+ }
+
+ if (tb[NFQA_IFINDEX_OUTDEV-1]) {
+ u_int32_t ifi =
+ ntohl(*(u_int32_t *)NFA_DATA(tb[NFQA_IFINDEX_OUTDEV-1]));
+ printf("outdev=%u ", ifi);
+ }
+
+ if (tb[NFQA_PAYLOAD-1]) {
+ printf("payload_len=%d ", NFA_PAYLOAD(tb[NFQA_PAYLOAD-1]));
+ }
+
+ fputc('\n', stdout);
+
+ return id;
+}
+
+
+static int cb(struct nfqnl_q_handle *qh, struct nfgenmsg *nfmsg,
+ struct nfattr *nfa[], void *data)
+{
+ u_int32_t id = print_pkt(nfa);
+ printf("entering callback\n");
+ return nfqnl_set_verdict(qh, id, NF_ACCEPT, 0, NULL);
+}
+