#define __KERNEL__ #define MODULE #include <linux/kernel.h> #include <linux/module.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv4.h> #include <linux/skbuff.h> #include <linux/udp.h> #include <linux/ip.h> #include <net/ip.h> #include <linux/inet.h> static struct nf_hook_ops netfilter_ops_in; /* NF_IP_PRE_ROUTING */ static struct nf_hook_ops netfilter_ops_out; /* NF_IP_POST_ROUTING */ /* Function prototype in <linux/netfilter> */ unsigned int main_hook(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff*)) { struct iphdr *iph = (struct iphdr *)skb_network_header(skb); if (htonl (in_aton("192.168.0.1")) == htonl(iph->saddr)){ **printk(KERN_ALERT "поймал пакет \n");** ---- тут условие, по которому я ловлю пакеты } return NF_ACCEPT; /* Allow ALL Packets */ } int init_module() { netfilter_ops_in.hook = main_hook; netfilter_ops_in.pf = PF_INET; netfilter_ops_in.hooknum = 0; netfilter_ops_in.priority = NF_IP_PRI_FIRST; netfilter_ops_out.hook = main_hook; netfilter_ops_out.pf = PF_INET; netfilter_ops_out.hooknum = 4; netfilter_ops_out.priority = NF_IP_PRI_FIRST; nf_register_hook(&netfilter_ops_in); /* register NF_IP_PRE_ROUTING hook */ nf_register_hook(&netfilter_ops_out); /* register NF_IP_POST_ROUTING hook */ return 0; } void cleanup_module() { nf_unregister_hook(&netfilter_ops_in); /*unregister NF_IP_PRE_ROUTING hook*/ nf_unregister_hook(&netfilter_ops_out); /*unregister NF_IP_POST_ROUTING hook*/ } Tell me, what methods do I change the destination address of the packet, recalculate the hash and send it to the port?