【问题标题】:C procedure entry point inet_ntop WS2_32.dll on XP?XP上的C程序入口点inet_ntop WS2_32.dll?
【发布时间】:2013-11-30 04:11:47
【问题描述】:

我在 windows xp 上收到错误“过程入口点 inet_ntop 无法位于动态链接库 WS2_32.dll 中”,经过一番谷歌搜索后,我发现 inet_ntop 在 XP 中不可用,所以我制作了一个宏请改用 inet_ntoa。但它似乎没有工作,我仍然得到同样的错误......我错过了什么吗?

char *get_ip(char *host)
{
    struct hostent *hent;
    int iplen = 39;
    long errorcode;
    char *ip = (char *)malloc(iplen + 1);
    memset(ip, 0, iplen + 1);

    if ((hent = gethostbyname(host)) == NULL)
    {
        perror("Could not get the IP address");
        exit(1);
    }

#if (_WIN32_WINNT >= 0x600)
    if (inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, iplen) == NULL)
    {
        perror("Could not resolve the host");
        exit(1);
    }
#else
    ip = inet_ntoa(*((struct in_addr *)hent->h_addr_list[0]));
    if (ip == NULL)
    {
        perror("Could not resolve the host");
        exit(1);
    }
#endif

    return ip;
}

【问题讨论】:

    标签: c windows windows-xp


    【解决方案1】:

    您的代码需要在运行时切换行为。相反,它使用条件编译来确定编译时的行为。您的#if 代码在编译时进行评估。不是你想要的我所期望的。实际上只编译了这些分支中的一个。再说一次,我敢肯定,这不是你所期望的。

    您需要使用运行时链接(LoadLibrary 和 GetProcAddress)并在运行时检查操作系统的版本以确定行为。

    【讨论】:

      猜你喜欢
      • 2018-01-02
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 2023-03-23
      • 1970-01-01
      • 2013-04-18
      相关资源
      最近更新 更多