【问题标题】:dereferencing pointer to incomplete type ‘struct tcphdr’?取消引用指向不完整类型“struct tcphdr”的指针?
【发布时间】:2020-09-10 10:11:01
【问题描述】:
【问题讨论】:
标签:
c
sockets
networking
libpcap
libnet
【解决方案1】:
在以下变化之后,人们会发生变化,包括来来去去:
@@ -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 包括在内 - 似乎不再是这种情况了,你必须为struct tcphdr 自己包括netinet/tcp.h。