static inline int SetPktHdr ( NfqImpl* impl, struct nfq_data* nfad, DAQ_PktHdr_t* hdr, uint8_t** pkt ) { int len = nfq_get_payload(nfad, (char**)pkt); if ( len <= 0 ) return -1; hdr->caplen = ((uint32_t)len <= impl->snaplen) ? (uint32_t)len : impl->snaplen; hdr->pktlen = len; hdr->flags = 0; hdr->address_space_id = 0; // if nfq fails to provide a timestamp, we fall back on tod if ( nfq_get_timestamp(nfad, &hdr->ts) ) gettimeofday(&hdr->ts, NULL); hdr->ingress_index = nfq_get_physindev(nfad); hdr->egress_index = -1; hdr->ingress_group = -1; hdr->egress_group = -1; return 0; }
static u_int32_t print_pkt (struct nfq_data *tb) { int id = 0; struct nfqnl_msg_packet_hdr *ph; struct nfqnl_msg_packet_hw *hwph; u_int32_t mark,ifi; int ret; char *data; ph = nfq_get_msg_packet_hdr(tb); if (ph) { id = ntohl(ph->packet_id); printf("hw_protocol=0x%04x hook=%u id=%u ", ntohs(ph->hw_protocol), ph->hook, id); } hwph = nfq_get_packet_hw(tb); if (hwph) { int i, hlen = ntohs(hwph->hw_addrlen); printf("hw_src_addr="); for (i = 0; i < hlen-1; i++) printf("%02x:", hwph->hw_addr[i]); printf("%02x ", hwph->hw_addr[hlen-1]); } mark = nfq_get_nfmark(tb); if (mark) printf("mark=%u ", mark); ifi = nfq_get_indev(tb); if (ifi) printf("indev=%u ", ifi); ifi = nfq_get_outdev(tb); if (ifi) printf("outdev=%u ", ifi); ifi = nfq_get_physindev(tb); if (ifi) printf("physindev=%u ", ifi); ifi = nfq_get_physoutdev(tb); if (ifi) printf("physoutdev=%u ", ifi); ret = nfq_get_payload(tb, &data); if (ret >= 0) { printf("payload_len=%d ", ret); //processPacketData (data, ret); } fputc('\n', stdout); return id; }
static inline int SetPktHdr ( NfqImpl* impl, struct nfq_data* nfad, DAQ_PktHdr_t* hdr, uint8_t** pkt ) { int len = nfq_get_payload(nfad, (char**)pkt); if ( len <= 0 ) return -1; hdr->caplen = ((uint32_t)len <= impl->snaplen) ? (uint32_t)len : impl->snaplen; hdr->pktlen = len; hdr->flags = 0; nfq_get_timestamp(nfad, &hdr->ts); hdr->device_index = nfq_get_physindev(nfad); return 0; }
int payload_get_physindev(struct payload *self) { return nfq_get_physindev(self->nfad); }