- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用套接字捕获 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 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 */
最佳答案
最后,我通过探索解决了这个问题。
主要问题是构建命令。
project -> peoperties -> C/C++ -> Language -> C Language standard 选择正确的标准,例如 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
时是不同的。
关于c - 取消引用指向不完整类型 tcphdr->members 的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49880294/
我使用套接字捕获 tcp 数据但构建失败。我的环境是visual studio 2017。我得到错误: 1>/root/projects/frame_capture/framecapture.c:1
这是 recv() 的奇怪行为。我正在使用libnetfilter_queue图书馆和iptables为了根据源端口将传入数据包存储到三个不同的队列中(由于下面编写的 iptables 规则,我检查了
我发现有两种不同的结构来获取 TCP header ,即 tcp 和 tcphdr。两个结构的链接都是 here:tcp和 here:tcphdr分别。 它们之间有什么区别,它们是否取决于所运行的系统
我正在完成一项作业,其中一部分涉及使用 pcap 捕获数据包。我关注了 tutorial ,现在正在尝试我找到的一些代码 here , 这与此类似: //#define __USE_BSD //#de
我已经在 OS/X 上开发了一些网络代码,我对 struct tcphdr 中重命名的字段感到厌恶。我收到了一堆格式错误:"dpkt.c:597:36: error: ‘struct tcphdr’
我在一个小型防火墙上工作,我必须从端口 80 (http) 的每个 tcp 数据包中检索数据以解析它们。这段代码在 debian 32 位虚拟机上运行良好,我能够打印每个网页的标题,但是当我尝试加载我
我们正在尝试为 linux 内核实现一个 NAT 模块。面临的问题是,对于传入 Hook 处的 TCP 数据包,预期指向目标端口的指针并没有这样做。传出钩子(Hook)的片段: unsigned in
玩转 http://www.tcpdump.org/sniffex.c获取数据包选项。 void payload (char *data) { // data contains full copied
我是一名优秀的程序员,十分优秀!