C PCAP library unknown types error

会有一股神秘感。 提交于 2019-12-03 12:15:42

问题


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?


回答1:


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.




回答2:


Try adding

     -D_BSD_SOURCE

az a CFLAG to your Makefile.



来源:https://stackoverflow.com/questions/15393905/c-pcap-library-unknown-types-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!