c-取消引用指向不完整类型"struct-tcphdr"的指针



我正在尝试编译"例11-9。SYNplescan工具的源代码";从这本关于Ubuntu 18.04的网络安全工具书: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.hlibnet.h或可能被pcap.h包含,似乎就不再是这样了,你必须自己将netinet/tcp.h包含在struct tcphdr中。

最新更新