我使用socket来捕获tcp数据,但构建失败。 我的环境是2017年的视觉工作室。 我收到了错误信息:
1>/root/projects/frame_capture/framecapture.c:199:60:error : dereferencing pointer to incomplete type
1> int header_size = sizeof(struct ethhdr) + iphdrlen + (tcph->doff) * 4;
另外,visual studio 2017命令行是:
"gcc" -W"switch" -W"no-deprecated-declarations" -W"empty-body" -W"conversion" -W"return-type" -W"parentheses" -W"no-pointer-sign" -W"no-format" -W"uninitialized" -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -std=c++14 -x c -Wall -fno-strict-aliasing -g2 -gdwarf-2 "g++" -O0 "3600000" -fthreadsafe-statics -W"switch" -W"no-deprecated-declarations" -W"empty-body" -W"conversion" -W"return-type" -W"parentheses" -W"no-format" -W"uninitialized" -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -frtti -fno-omit-frame-pointer -std=c11 -fexceptions -o "D:\linuxCproject\frame_capture\frame_capture\obj\x64\Debug\%(filename).o"
我在linux中使用gcc构建它都取得了成功。 linux代码:
[root@localhost netinet]# gcc -o o.out framecapture.c
我想知道如何在visual studio中解决这个问题。 代码行:
unsigned short iphdrlen;
struct iphdr *iph = (struct iphdr *)(Buffer + sizeof(struct ethhdr));
iphdrlen = iph->ihl * 4;
struct tcphdr *tcph = (struct tcphdr*)(Buffer + iphdrlen + sizeof(struct ethhdr));
int header_size = sizeof(struct ethhdr) + iphdrlen + (tcph->doff) * 4;
但是我像这样包含.h文件:
#include<netinet/tcp.h> //Provides declarations for tcp header
tcp.h中的定义是:
# else /* !__FAVOR_BSD */
struct tcphdr
{
u_int16_t source;
u_int16_t dest;
u_int32_t seq;
u_int32_t ack_seq;
# if __BYTE_ORDER == __LITTLE_ENDIAN
u_int16_t res1:4;
u_int16_t doff:4;
u_int16_t fin:1;
u_int16_t syn:1;
u_int16_t rst:1;
u_int16_t psh:1;
u_int16_t ack:1;
u_int16_t urg:1;
u_int16_t res2:2;
# elif __BYTE_ORDER == __BIG_ENDIAN
u_int16_t doff:4;
u_int16_t res1:4;
u_int16_t res2:2;
u_int16_t urg:1;
u_int16_t ack:1;
u_int16_t psh:1;
u_int16_t rst:1;
u_int16_t syn:1;
u_int16_t fin:1;
# else
# error "Adjust your <bits/endian.h> defines"
# endif
u_int16_t window;
u_int16_t check;
u_int16_t urg_ptr;
};
# endif /* __FAVOR_BSD */
答案 0 :(得分:0)
最后,我通过探索解决了这个问题。
主要问题是构建命令。
项目 - &gt; peoperties - &gt; C / C ++ - &gt;语言 - &gt; C语言标准chosse正确标准如C99 / C89或其他,我选择Default解决了编译问题。设置c ++语言标准与C相同,我也是默认的。
之后我得到命令行:
"gcc" -W"switch" -W"no-deprecated-declarations" -W"empty-body" -W"conversion" -W"return-type" -W"parentheses" -W"no-pointer-sign" -W"no-format" -W"uninitialized" -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -Wall -fno-strict-aliasing -g2 -gdwarf-2 "g++" -O0 "3600000" -fthreadsafe-statics -W"switch" -W"no-deprecated-declarations" -W"empty-body" -W"conversion" -W"return-type" -W"parentheses" -W"no-format" -W"uninitialized" -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -frtti -fno-omit-frame-pointer -fexceptions -o "D:\linuxCproject\icmprequest\icmprequest\obj\x64\Debug\%(filename).o"
提示:处理!__FAVOR_BSD
时,不同的标准会有所不同。