相关疑难解决方法(0)

如何从debian 64位上的tcphdr(sk_buff)结构访问数据/有效负载?

我正在使用一个小型防火墙,我必须从端口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)

c network-programming netfilter kernel-module

4
推荐指数
1
解决办法
1万
查看次数

C - Linux - 内核模块 - TCP头

我正在尝试创建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)

c kernel tcp module ipv4

3
推荐指数
2
解决办法
9008
查看次数

netfilter-like内核模块获取源和目标地址

我阅读本指南来编写内核模块来进行简单的网络过滤.

首先,我不知道这意味着什么,以及入站和出站数据包(通过传输层)之间的区别是什么?

当数据包从线路进入时,它会从物理层,数据链路层,网络层向上传播,因此它可能无法通过netfilter中定义的功能来使skb_transport_header工作.

其次,我讨厌幻数,我想20用linux内核的实用程序(源文件)中的任何函数替换(典型IP头的长度).

任何帮助将不胜感激.

linux kernel-module linux-kernel

1
推荐指数
1
解决办法
1179
查看次数