C语言 无法编译ecepass.c
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44640775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to compile ecepass.c
提问by sethh
I can not for the life of me compile this old code. I'm attempting to use it to test external vulnerabilities for a client. I have it running in FreeBSD 11 and compiling with gcc. Any idea why I'm getting this error?
我终生无法编译这段旧代码。我正在尝试使用它来测试客户端的外部漏洞。我让它在 FreeBSD 11 中运行并使用 gcc 进行编译。知道为什么我会收到此错误吗?
int in_cksum(u_short *addr, int len)
{
int sum;
int nleft;
u_short ans;
u_short *w;
sum = 0;
ans = 0;
nleft = len;
w = addr;
while (nleft > 1) {
sum += *w++;
nleft -= 2;
}
if (nleft == 1) {
*(u_char *)(&ans) = *(u_char *)w;
sum += ans;
}
return (sum);
}
Full code here: https://pastebin.com/MGSYycmB
完整代码在这里:https: //pastebin.com/MGSYycmB
Error:
错误:
In file included from ecepass.c:8:0: ecepass.c:72:5: error: expected declaration specifiers or '...' before numeric constant int in_cksum(u_short *addr, int len)
在 ecepass.c:8:0 包含的文件中:ecepass.c:72:5: 错误:预期的声明说明符或 '...' 之前的数字常量 int in_cksum(u_short *addr, int len)
回答by CristiFati
In the code posted on pastebin, at line #8(and #24:d) there's the statement: #include <machine/in_cksum.h>
在pastebin 上发布的代码中,第 8行(和第 24 行:d)有以下语句:#include <machine/in_cksum.h>
As I'm not on Ux, I've searched the file on Internet and found 2 references:
由于我不在Ux 上,我在 Internet 上搜索了该文件并找到了 2 个参考文献:
- [GitHub]: osv/bsd/x64/machine/in_cksum.h
- [RTEMS]: source:rtems-libbsd/freebsd/sys/arm/include/machine/in_cksum.h @ ffcd542
- [GitHub]: osv/bsd/x64/machine/in_cksum.h
- [RTEMS]:来源:rtems-libbsd/freebsd/sys/arm/include/machine/in_cksum.h@ffcd542
In both of them (around line #40+), seems like in_cksumis a preprocessor macro:
在它们两个中(围绕第#40+ 行),似乎in_cksum是一个预处理器宏:
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
Change the name of your function (and all the places in your code that reference it) to something that's not a macro, or another defined identifier as a matter of fact, e.g. checksum(hopefully it's not already defined :) ), and you should be fine (might apply to other of your functions as well).
Or as an alternative, remove the machine/in_cksum.hinclusion (direct andindirect (via other nested includes)), but this might get a little bit more difficult (also, I didn't check all the code to see if other functions from the include are used).
将函数的名称(以及代码中引用它的所有位置)更改为不是宏的名称,或者实际上不是另一个定义的标识符,例如checksum(希望它尚未定义:)),您应该很好(也可能适用于您的其他功能)。
或者作为替代,删除machine/in_cksum.h包含(直接和间接(通过其他嵌套包含)),但这可能会变得更困难(另外,我没有检查所有代码以查看其他函数从包含使用)。

