错误:解除指向不完整types的指针

我有一个结构定义为

50 struct nf_hook_state { 51 unsigned int hook; 52 int thresh; 53 u_int8_t pf; 54 struct net_device *in; 55 struct net_device *out; 56 struct sock *sk; 57 struct net *net; 58 struct list_head *hook_list; 59 int (*okfn)(struct net *, struct sock *, struct sk_buff *); 60 }; 

在我的代码中,我试图访问它,如下所示:

 unsigned int my_packet_pass_through_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { switch(state->hook){ 

编译时,它给我错误:

 error: dereferencing pointer to incomplete type 'const struct nf_hook_state' switch(state->hook){ 

有人可以build议我在这里做什么错?

您需要#include包含nf_hook_state struct的头文件,否则在编译该翻译单元时编译器不知道该struct的布局。

如果它不在特定的头文件中,那么就是相应地重构代码的时候了。