我使用套接字捕获tcp数据,但构建失败。我的环境是visual studio 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 headertcp.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 */发布于 2018-05-10 17:26:34
最后,我通过自己的探索解决了这个问题。
主要的问题是构建命令。
-> -> C/C++ -> Language -> C语言标准选择了C99/C89等正确的标准,我选择了缺省值,解决了编译问题。将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时,不同的标准是不同的。
https://stackoverflow.com/questions/49880294
复制相似问题