c - Error message "dereferencing pointer to incomplete type" when I use udphdr -
i write programme udphdr.h
. , here header file list:
#include <linux/module.h> #include <linux/kernel.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv4.h> #include <linux/ip.h> #include <linux/tcp.h> #include <linux/udp.h> #include <linux/skbuff.h> #include <linux/init.h> #include <linux/types.h> #include <linux/sched.h> #include <net/sock.h> #include <linux/netlink.h>
and here code:
void dealudph(struct updhr* udph){ if(udph==null){ printk("udph null!!\n"); }else{ printk("updh %u\n",udph); printk("udp sport %u\n",udph->source); } } static unsigned int hookfunc(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=ip_hdr(skb); struct ethhdr * ethh = eth_hdr(skb); struct tcphdr *tcph=tcp_hdr(skb); struct udphdr *udph=udp_hdr(skb); printk("*********************************************************\n"); dealiph(iph); dealethh(ethh); dealtcph(tcph); dealudph(udph); printk("*********************************************************\n"); return nf_accept; }
here makefile:
ifneq ($(kernelrelease),) mymodule-objs:=main.c obj-m += main.o else pwd := $(shell pwd) kver := $(shell uname -r) kdir := /lib/modules/$(kver)/build all: $(make) -c $(kdir) m=$(pwd) modules clean: rm -rf *.o *.mod.c *.ko *.symvers *order *.markers *- endif
when compile file, says line: printk("udp sport %u\n",udph->source);
error, , error information dereferencing pointer incomplete type
.
what matter? how solve it?
you have:
struct updhr* udph
you mean:
struct udphdr* udph
(in context of: void dealudph(struct updhr* udph){
.)
note long don't need reference members in structure, or allocate copy of structure, can use struct anynameyoulike *ptr
parameter without further ado. however, if name appears first time in function prototype (declaration or definition), should warnings like:
$ gcc -g -o3 -std=c11 -wall -wextra -wmissing-prototypes -werror -c xx.c xx.c:2:23: error: ‘struct xyz’ declared inside parameter list [-werror] void something(struct xyz *ptr) ^ xx.c:2:23: error: scope definition or declaration, not want [-werror] xx.c:2:6: error: no previous prototype ‘something’ [-werror=missing-prototypes] void something(struct xyz *ptr) ^ cc1: warnings being treated errors rmk: error code 1 $
the 'no previous prototype' message accurate , consequence of using -wmissing-prototypes
option (in conjunction -werror
).
xx.c
#include <stdlib.h> void something(struct xyz *ptr) { if (ptr == 0) exit(0); }
Comments
Post a Comment