5 #include <netinet/in.h>
7 #include <libnetfilter_log/libnetfilter_log.h>
9 static int print_pkt(
struct nflog_data *ldata)
20 printf(
"hw_protocol=0x%04x hook=%u ",
21 ntohs(ph->hw_protocol), ph->hook);
24 printf(
"mark=%u ", mark);
27 printf(
"indev=%u ", indev);
30 printf(
"outdev=%u ", outdev);
34 printf(
"prefix=\"%s\" ", prefix);
37 printf(
"payload_len=%d ", payload_len);
44 struct nflog_data *nfa,
void *data)
51 int main(
int argc,
char **argv)
61 fprintf(stderr,
"error during nflog_open()\n");
65 printf(
"unbinding existing nf_log handler for AF_INET (if any)\n");
67 fprintf(stderr,
"error nflog_unbind_pf()\n");
71 printf(
"binding nfnetlink_log to AF_INET\n");
73 fprintf(stderr,
"error during nflog_bind_pf()\n");
76 printf(
"binding this socket to group 0\n");
79 fprintf(stderr,
"no handle for grup 0\n");
83 printf(
"binding this socket to group 100\n");
86 fprintf(stderr,
"no handle for group 100\n");
90 printf(
"setting copy_packet mode\n");
92 fprintf(stderr,
"can't set packet copy mode\n");
98 printf(
"registering callback for group 0\n");
99 nflog_callback_register(qh, &cb, NULL);
101 printf(
"going into main loop\n");
102 while ((rv = recv(fd, buf,
sizeof(buf), 0)) && rv >= 0) {
103 printf(
"pkt received (len=%u)\n", rv);
106 nflog_handle_packet(h, buf, rv);
109 printf(
"unbinding from group 100\n");
111 printf(
"unbinding from group 0\n");
117 printf(
"unbinding from AF_INET\n");
121 printf(
"closing handle\n");
uint32_t nflog_get_outdev(struct nflog_data *nfad)
struct nflog_handle * nflog_open(void)
int nflog_set_mode(struct nflog_g_handle *gh, uint8_t mode, uint32_t range)
int nflog_get_payload(struct nflog_data *nfad, char **data)
uint32_t nflog_get_indev(struct nflog_data *nfad)
int nflog_unbind_pf(struct nflog_handle *h, uint16_t pf)
uint32_t nflog_get_nfmark(struct nflog_data *nfad)
struct nflog_g_handle * nflog_bind_group(struct nflog_handle *h, uint16_t num)
int nflog_bind_pf(struct nflog_handle *h, uint16_t pf)
int nflog_unbind_group(struct nflog_g_handle *gh)
int nflog_close(struct nflog_handle *h)
char * nflog_get_prefix(struct nflog_data *nfad)
int nflog_fd(struct nflog_handle *h)
struct nfulnl_msg_packet_hdr * nflog_get_msg_packet_hdr(struct nflog_data *nfad)