11

I installed the pcap library on my linux system but when including it I get the errors

 /usr/include/pcap/bpf.h:88:1: error: unknown type name ‘u_int’
 /usr/include/pcap/bpf.h:108:2: error: unknown type name ‘u_int’
 /usr/include/pcap/bpf.h:1260:2: error: unknown type name ‘u_short’
 /usr/include/pcap/bpf.h:1261:2: error: unknown type name ‘u_char’
 /usr/include/pcap/bpf.h:1262:2: error: unknown type name ‘u_char’
 In file included from ../src/test.c:1:0:
 /usr/include/pcap/pcap.h:125:2: error: unknown type name ‘u_short’
 /usr/include/pcap/pcap.h:126:2: error: unknown type name ‘u_short’
 /usr/include/pcap/pcap.h:171:2: error: unknown type name ‘u_int’
 ...
 make: *** [src/test.o] Error 1

I included

 #include <pcap/pcap.h>
 #include <sys/types.h>
 #include <pcap-bpf.h>

in the program, what am I missing?

wasp256
  • 5,355
  • 9
  • 53
  • 94

2 Answers2

12

Make sure you do NOT define any of:

  • __STRICT_ANSI__
  • _ISOC99_SOURCE
  • _POSIX_SOURCE
  • _POSIX_C_SOURCE
  • _XOPEN_SOURCE
  • _SVID_SOURCE

when building your program; they may prevent the BSD data types, such as the ones the compile is complaining about, from being defined.

  • No I didn't I simply compile it with 'gcc -std=c99 test.c -o test' – wasp256 Mar 13 '13 at 19:26
  • 4
    Actually, yes, you *did* define at least one of them, by specifying `-std=c99`. The GCC man page says `-std=` has the same effect as `-ansi`, and `-ansi` defines `__STRICT_ANSI__`. `-std=c99` may define `_ISOC99_SOURCE` as well as, or instead of, `__STRICT_ANSI__`. `-std=c99` means you want your code to be compiled as strict ISO C99, meaning it can't use any features not in ISO C99 - and libpcap isn't in ISO C99, so.... If you're trying to use C99 features and they're not supported by default, try `-std=gnu99`. –  Mar 13 '13 at 19:32
11

Try adding

     -D_BSD_SOURCE

az a CFLAG to your Makefile.

molnarg
  • 435
  • 4
  • 8
  • 6
    Alternatively, consider `-D_GNU_SOURCE`. This will allow you to use features derived from BSD without linking the BSD compatibility library. See the [GNU documentation on feature test macros](https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html) for more information on the different values that can be specified and when you need to use the BSD compatibility library. – Trevor A. Sep 19 '13 at 12:59