Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';由于endianess的错误,无法使用tcp.h编译简单程序?_C_Tcp_Compiler Errors_Sniffing_Man In The Middle - Fatal编程技术网

Can';由于endianess的错误,无法使用tcp.h编译简单程序?

Can';由于endianess的错误,无法使用tcp.h编译简单程序?,c,tcp,compiler-errors,sniffing,man-in-the-middle,C,Tcp,Compiler Errors,Sniffing,Man In The Middle,帮我用tcp.h编译这个简单的C程序?获取“mitmc.c:82:error:struct tcphdr没有名为th_off的成员”,因为字节顺序未设置为“#ifdef u FAVOR_BSD” 对于你们中的一些人来说,这是一个简单的问题。我试图编写程序,一个简单的人在中间的实用工具从一本书。在linux上使用gcc编译(因为Windows没有posix库) 首先我得到了这个错误: mitmc.c: In function âcorrupt_ip_pktâ: mitmc.c:82: error:

帮我用tcp.h编译这个简单的C程序?获取“mitmc.c:82:error:struct tcphdr没有名为th_off的成员”,因为字节顺序未设置为“#ifdef u FAVOR_BSD”

对于你们中的一些人来说,这是一个简单的问题。我试图编写程序,一个简单的人在中间的实用工具从一本书。在linux上使用gcc编译(因为Windows没有posix库)

首先我得到了这个错误:

mitmc.c: In function âcorrupt_ip_pktâ:
mitmc.c:82: error: âstruct tcphdrâ has no member named âth_offâ
mitmc.c:109: error: âstruct udphdrâ has no member named âuh_ulenâ
看起来这是因为在“/usr/include/netinet/tcp.h”中,只有当 #如果你喜欢

但当我通过添加 #定义_BSD_源 (因为它是在features.h中设置的),所以我得到了一整套其他错误:

$ gcc mitmc.c
/tmp/ccuzRcNp.o: In function `corrupt_ip_pkt':
mitmc.c:(.text+0x15f): undefined reference to `libnet_do_checksum'
mitmc.c:(.text+0x174): undefined reference to `libnet_geterror'
mitmc.c:(.text+0x231): undefined reference to `libnet_do_checksum'
mitmc.c:(.text+0x242): undefined reference to `libnet_geterror'
mitmc.c:(.text+0x296): undefined reference to `libnet_do_checksum'
mitmc.c:(.text+0x2a7): undefined reference to `libnet_geterror'
/tmp/ccuzRcNp.o: In function `pkt_handler':
mitmc.c:(.text+0x346): undefined reference to `libnet_write_raw_ipv4'
mitmc.c:(.text+0x357): undefined reference to `libnet_geterror'
/tmp/ccuzRcNp.o: In function `main':
mitmc.c:(.text+0x466): undefined reference to `libnet_init'
mitmc.c:(.text+0x4ae): undefined reference to `libnet_get_hwaddr'
mitmc.c:(.text+0x4c6): undefined reference to `libnet_geterror'
mitmc.c:(.text+0x590): undefined reference to `strlcat'
mitmc.c:(.text+0x5c0): undefined reference to `strlcat'
mitmc.c:(.text+0x5df): undefined reference to `pcap_lookupdev'
mitmc.c:(.text+0x63c): undefined reference to `pcap_lookupnet'
mitmc.c:(.text+0x697): undefined reference to `pcap_open_live'
mitmc.c:(.text+0x6fc): undefined reference to `pcap_compile'
mitmc.c:(.text+0x715): undefined reference to `pcap_perror'
mitmc.c:(.text+0x736): undefined reference to `pcap_setfilter'
mitmc.c:(.text+0x74f): undefined reference to `pcap_perror'
mitmc.c:(.text+0x767): undefined reference to `pcap_freecode'
mitmc.c:(.text+0x7ad): undefined reference to `pcap_loop'
mitmc.c:(.text+0x7cd): undefined reference to `pcap_perror'
mitmc.c:(.text+0x7e6): undefined reference to `pcap_close'
mitmc.c:(.text+0x7f3): undefined reference to `libnet_destroy'
collect2: ld returned 1 exit status
谢谢你的帮助

另外,顺便说一句,为什么我的编译器错误有时用–而不是引号? 谢谢,在bash中使用LANG=C修复了引号

在这里重复回答,以便我可以使用格式。 杰出的我不知道libnet config是可以在命令行上用于设置的二进制文件。所以对于其他的noob

$ libnet-config  --defines
-D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H
$ libnet-config --libs
-lnet
因此,您可以将其转义,使其作为命令运行

$ gcc -Wall `libnet-config --defines` mitmc.c -o mitmc `libnet-config --libs` -lpcap
mitmc.c: In function 'main':
mitmc.c:232: warning: implicit declaration of function 'strlcat'
/tmp/ccSDMkcZ.o: In function `main':
mitmc.c:(.text+0x590): undefined reference to `strlcat'
mitmc.c:(.text+0x5c0): undefined reference to `strlcat'
collect2: ld returned 1 exit status
谢谢你的帮助,这是正确的答案。现在看来,代码是为openbsd编写的(参见wikipedia Strlcpy)。我想我会用strncpy代替strlcat,希望一切都好。成功吧!哦,

$ sudo ./mitmc
pcap_compile: syntax error
啊,这就是我的用法


谢谢你,弗拉德,谢谢你,耶利米

为了使用
libnet
,您必须为编译器/链接器指定特定的标志。在本例中,您会看到链接器错误,因为它无法找到您在程序中使用的函数的定义。显然,这是因为您需要链接到
libnet
libpcap
。要正确操作,请尝试以下操作:

gcc -Wall `libnet-config --defines` mitmc.c -o mitmc `libnet-config --libs` -lpcap

替换引号的奇数字符来自您的区域设置;如果编译时将
LANG
环境变量设置为
C
,则会得到正常的引号。对不起,我不知道,可能有一个针对傻瓜的编译常见问题解答?我认为编译器是新的,因为#include语句。噢,哇,对于另一个无知的人来说,libnet config实际上生成了要使用的输出libnet config--defines-D_BSD_SOURCE-D_BSD_SOURCE-D_FAVOR_BSD-DHAVE_NET_ETHERNET_ht编译器知道编译时标识符,因为您告诉编译器将源代码包含在.h文件中。这不会告诉链接器什么。你必须单独告诉链接器。同样的事情也发生在VisualStudio和其他系统中。