In my project, I include pfring.h, but compile error: some functions in net/if.h and linux/if.h are redefinition. I found that the pfring.h include linux/if.h So, I test a program, my test code:
#include <linux/if.h>
#include <net/if.h>
int main(void) {
return 0;
}
It expected compile error. So, what's wrong with linux/if.h and net/if.h ? Can not I include them at once?
error message:
In file included from test.c:1:0:
/usr/include/linux/if.h:178:19: error: field 'ifru_addr' has incomplete type
/usr/include/linux/if.h:179:19: error: field 'ifru_dstaddr' has incomplete type
/usr/include/linux/if.h:180:19: error: field 'ifru_broadaddr' has incomplete type
/usr/include/linux/if.h:181:19: error: field 'ifru_netmask' has incomplete type
/usr/include/linux/if.h:182:20: error: field 'ifru_hwaddr' has incomplete type
In file included from test.c:2:0:
/usr/include/net/if.h:45:5: error: expected identifier before numeric constant
/usr/include/net/if.h:112:8: error: redefinition of 'struct ifmap'
/usr/include/linux/if.h:136:8: note: originally defined here
/usr/include/net/if.h:127:8: error: redefinition of 'struct ifreq'
/usr/include/linux/if.h:170:8: note: originally defined here
/usr/include/net/if.h:177:8: error: redefinition of 'struct ifconf'
/usr/include/linux/if.h:219:8: note: originally defined here
For me (on Ubuntu 12.04 x64) the following include solved the problem:
#include <sys/socket.h> // <-- This one
#include <linux/if.h>
#include <linux/if_tun.h>
This problem has been resolved, add the compile flag -DHAVE_PCAP is fix. ;-)
At first let us talk about the source: The header files are from different Packages as you can see asking dpkg
.
$ dpkg -S /usr/include/linux/if.h
linux-libc-dev:i386: /usr/include/linux/if.h
$ dpkg -S /usr/include/net/if.h
libc6-dev:i386: /usr/include/net/if.h
linux-libc-dev
is part of linux kernel packages while libc6-dev
is part of the libc6
(Standard C library in version 6).
It seams like they are interchangeable so you should only use one (not 100% sure about this). If you pick linux/if.h
, you may depend on Kernel versions with your compiled binary.
All new Library versions I have in mind stick with net/if.h
instead of the linux one - so you should do the same.
If you are using one of the interface state flags (eg: IFF_UP, etc.), you need one more header than mentioned in other posts.
#include <sys/types.h> // <==
#include <sys/socket.h>
#include <linux/if.h>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With