我正在尝试打印TCP地址,但我得到“解除指向不完整类型的指针”错误。我认为iphdr
类型转换不起作用。我该如何解决这个问题?
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 *ip_header; // ip header struct
if (!skb)
return NF_ACCEPT;
ip_header = (struct iphdr *)skb_network_header(skb); /* I think this is not working */
printk("addr : %lu.\n",ip_header->saddr);
return NF_ACCEPT;
}
int init_module()
{
printk(KERN_INFO "initialize kernel module\n");
/* Fill in our hook structure */
nfho.hook = hook_func; /* Handler function */
nfho.hooknum = NF_INET_PRE_ROUTING; /* First hook for IPv4 */
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST; /* Make our function first */
nf_register_hook(&nfho);
return 0;
}
答案 0 :(得分:0)
对于testDomain(...
类型的dereferece指针,您需要
struct iphdr
(实际上,此类型在#include <linux/ip.h>
中定义,但通常在include/uapi/linux/ip.h
下的标题包含在其他标题中。)