【问题标题】:"error: 'struct udphdr' has no member named 'source'" ... huh?“错误:‘struct udphdr’没有名为‘source’的成员”……嗯?
【发布时间】:2010-09-17 20:32:33
【问题描述】:

我正在尝试编译一个名为 ngrep 的程序,当我运行 configure 时,一切似乎都很顺利,但是当我运行 make 时,我得到:

ngrep.c: In function ‘process’:
ngrep.c:544: error: ‘struct udphdr’ has no member named ‘source’
ngrep.c:545: error: ‘struct udphdr’ has no member named ‘dest’
make: *** [ngrep.o] Error 1                              

这是什么意思,我该如何解决?没有早期的警告或错误提示问题的根源。

【问题讨论】:

    标签: c linux unix ngrep


    【解决方案1】:

    发现问题:

    #ifdef HAVE_DUMB_UDPHDR
                    printf("%s:%d -", inet_ntoa(ip_packet->ip_src), ntohs(udp->source));
                    printf("> %s:%d", inet_ntoa(ip_packet->ip_dst), ntohs(udp->dest));
    #else
                    printf("%s:%d -", inet_ntoa(ip_packet->ip_src), ntohs(udp->uh_sport));
                    printf("> %s:%d", inet_ntoa(ip_packet->ip_dst), ntohs(udp->uh_dport));
    #endif
    

    显然,configure 在这个测试中有一个错误,它认为我的系统有“哑”udphdr,即使它没有。将第一行更改为“#if 0”可以解决问题。

    【讨论】:

    • 在 macOS 中,ntohs(tcpHeader->source) 应更改为 ntohs(tcpHeader->th_sport)ntohs(tcpHeader->dest) 应更改为 ntohs(tcpHeader->th_dport)
    【解决方案2】:

    嗯,有一个名为 udphdr 的结构(可能是 udp 标头的缩写)。并且程序的某些部分假定结构具有它没有的成员 source 和 dest。

    查看文件 ngrep.c 的第 544 行和第 545 行以找到有问题的行。

    可能的原因:

    • 类型名称类型错误。
    • 结构未完全定义。
    • 使用了错误的结构。

    编辑:可能相关问题:http://ubuntuforums.org/showthread.php?t=371871

    【讨论】:

    • 感谢您的链接,但我已经安装了 build-essential,并且论坛链接的站点已不存在。
    猜你喜欢
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多