问题描述
我正在尝试从Ubuntu 18.04上的NetworkSecurityTools本书中编译“示例11-9。SYNplescan工具的源代码”: http://books.gigatux.nl/mirror/networksecuritytools/0596007949/networkst-CHP-11-SECT-4.html
但是它说
error: dereferencing pointer to incomplete type ‘struct tcphdr’
if (tcp->th_flags == 0x14)
^~
我该如何解决?
解决方法
在进行以下更改之后,人员会发生变化,包括来来去去
@@ -1,9 +1,12 @@
+#define _DEFAULT_SOURCE 1
#define _BSD_SOURCE 1
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <libnet.h>
#include <pcap.h>
+#include <netinet/tcp.h>
+#include <netinet/ip.h>
int answer = 0; /* flag for scan timeout */
@@ -42,7 +45,7 @@
int
main (int argc,char *argv[])
{
- char *device = NULL; /* device for sniffing/sending */
+ const char *device = NULL; /* device for sniffing/sending */
char o; /* for option processing */
in_addr_t ipaddr; /* ip address to scan */
u_int32_t myipaddr; /* ip address of this host */
我能够使用:
gcc -Wall 1.c -lnet -lpcap
,没有编译器消息。我想一旦netinet/tcp.h
或libnet.h
包含了pcap.h
以后,情况似乎就不再一样了,您必须为netinet/tcp.h
包含struct tcphdr
。