Home > other >  Windows 7 double nic bridge, how to realize the convection bridge connect network card Ip packets ma
Windows 7 double nic bridge, how to realize the convection bridge connect network card Ip packets ma

Time:10-03

Linux under the iptables to bridge IP packets to the application processing, determined by the application through the bridge IP packet is passed or rejected, how to implement this function under Windows 7? Urgent urgent!!! Such as online
The following implementation under Linux, Windows 7 system how to realize the function
//callback function definition, the basic structure is processing package first, then return to ruling
Static int cb (struct nfq_q_handle * qh, struct nfgenmsg * NFMSG, struct nfq_data * nfa, void * data)
{
//packet processing
U_int32_t id=print_pkt (nfa);
Printf (" if the callback \ n ");
//set the ruling
Return nfq_set_verdict (qh, id, NF_ACCEPT, 0, NULL);
}

Int main (int arg c, char * * argv)
{
Struct nfq_handle * h;
Struct nfq_q_handle * qh.
Struct nfnl_handle * nh;
Int fd.
Int the rv;
Char buf [4096].
Printf (" opening library handle \ n ");
//open nfq_handle
H=nfq_open ();
if (! H) {
Fprintf (stderr, "error during nfq_open () \ n");
exit(1);
}
Printf (" unbinding existing nf_queue handler for AF_INET (if any) \ n ");
//to solve and AF_INET binding
If (nfq_unbind_pf (h, AF_INET) & lt; 0 {
Fprintf (stderr, "error during nfq_unbind_pf () \ n");
exit(1);
}
Printf (" binding nfnetlink_queue as nf_queue handler for AF_INET \ n ");
//to bind to AF_INET
If (nfq_bind_pf (h, AF_INET) & lt; 0 {
Fprintf (stderr, "error during nfq_bind_pf () \ n");
exit(1);
}
Printf (" binding this socket to the queue '0' \ n ");
//build nfq_q_handle, number is 0, the callback function is a cb
//may establish multiple queue, distinguish with different number can
Qh=nfq_create_queue (h, 0, & amp; Cb, NULL);
if (! Qh) {
Fprintf (stderr, "error during nfq_create_queue () \ n");
exit(1);
}

Printf (" setting copy_packet mode \ n ");
//set copies of data model, the entire package copy
If (nfq_set_mode (qh, NFQNL_COPY_PACKET, 0 XFFFF) & lt; 0 {
Fprintf (stderr, "can 't set packet_copy mode \ n");
exit(1);
}

Nh=nfq_nfnlh (h);
Fd=nfnl_fd (nh);
//from netlink socket receiving data
While ((rv=recv (fd, buf, sizeof (buf), 0)) & amp; & The rv & gt;=0) {
Printf (" PKT received \ n ");
//process the data, you will call to the corresponding callback function
Nfq_handle_packet (h, buf, rv);
}

Printf (" unbinding from queue 0 \ n ");
//release queue
Nfq_destroy_queue (qh);

# ifdef INSANE
/* normally, applications SHOULD NOT issue this command, since
* it detaches other designed/sockets from AF_INET, too! */
Printf (" unbinding from AF_INET \ n ");
Nfq_unbind_pf (h, AF_INET);
# endif

Printf (" closing the library handle \ n ");
//close nfq_handle
Nfq_close (h);
exit(0);
}
  • Related