Listing 2. Sample Callback Function That Will Dump a Packet in Hex // Sample NF_QUEUE callback function. static int nfqueue_cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, struct nfq_data *nfa, void *data) { struct nfqnl_msg_packet_hdr *ph; int id = 0; int size = 0; int i; unsigned char *full_packet; unsigned char * c; struct in_addr ipa; char src_ip_str[20]; char dst_ip_str[20]; ph = nfq_get_msg_packet_hdr(nfa); if (ph) { // Print out metatdata. id = ntohl(ph->packet_id); fprintf(stdout, "hw_protocol = 0x%04x hook = %u id = %u\n", ntohs(ph->hw_protocol), ph->hook, id); // Retrieve packet payload. size = nfq_get_payload(nfa, &full_packet); // Get IP addresses in char form. ip = (struct iphdr *) full_packet; ipa.s_addr=ip->saddr strcpy (src_ip_str, inet_ntoa(ipa)); ipa.s_addr=ip->daddr; strcpy (dst_ip_str, inet_ntoa(ipa)); fprintf(stdout, "Source IP: %s Destination IP: %s\n", src_ip_str, dst_ip_str); // Print out packet in hex. c = (unsigned char *)payload; for (i=0; i