我正在使用一个小型防火墙,我必须从端口80(http)中的每个tcp数据包中检索数据以进行解析.这个代码适用于debian 32位虚拟机,我可以打印每个网页的标题,但是当我尝试加载我的内核模块并通过http端口传输一些数据时,它不打印任何数据.
当我编译时,它只在我的64位计算机上显示那些警告:
/home/dev3/C/FIREWALL/firewall.c: In function ‘hook_func’:
/home/dev3/C/FIREWALL/firewall.c:179: warning: cast from pointer to integer of different size
/home/dev3/C/FIREWALL/firewall.c:179: warning: cast to pointer from integer of different size
Run Code Online (Sandbox Code Playgroud)
有人有任何想法吗?
谢谢.
代码:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netfilter.h>
#undef __KERNEL__
#include <linux/netfilter_ipv4.h>
#define __KERNEL__
#include <linux/ip.h>
#include <linux/tcp.h>
static struct nf_hook_ops nfho;
unsigned int hook_func( 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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建linux内核模块,它将检查传入的数据包.目前,我正在提取数据包的TCP头并读取源和目标端口 - >但是我得到的值不正确.我有钩功能:
unsigned int hook_func(unsigned int hooknum, struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct iphdr *ipp = (struct iphdr *)skb_network_header(skb);
struct tcphdr *hdr;
/* Using this to filter data from another machine */
unsigned long ok_ip = 2396891328;
/* Some problem, empty network packet. Stop it now. */
if (!skb)
return NF_ACCEPT;
/* Just to track only packets coming from 1 IP */
if (ipp->saddr != ok_ip)
return NF_ACCEPT; …Run Code Online (Sandbox Code Playgroud)