macos 将 getifaddrs 移植到 Win XP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3069082/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:00:59  来源:igfitidea点击:

Porting getifaddrs to Win XP

c++macoswindows-xpipv6ipv4

提问by Goz

I'm trying to port a MacOSX app to windows and I've come up against a problem around getifaddrs. Basically windows does not support it. I'm trying to figure a way to re-implement it (for AF_INET and AF_INET6) but the "equivalent" functionality on windows appears to be nothing like the MacOSX support.

我正在尝试将 MacOSX 应用程序移植到 Windows,但遇到了有关 getifaddrs 的问题。基本上windows不支持它。我试图找到一种重新实现它的方法(对于 AF_INET 和 AF_INET6),但 Windows 上的“等效”功能似乎与 MacOSX 支持完全不同。

Has someone done this sort of conversion before? If so is there a nice way I can get windows to report me interface info like MacOSX does?

以前有人做过这种转换吗?如果是这样,是否有一种很好的方法可以让 Windows 像 MacOSX 一样报告我的界面信息?

回答by Laurent Etiemble

The closest functions on Windows are GetAdaptersInfoand GetAdaptersAddresses. The MSDN documentation is pretty comprehensive, so you should find everything you need.

Windows 上最接近的函数是GetAdaptersInfoGetAdaptersAddresses。MSDN 文档非常全面,因此您应该可以找到所需的一切。

回答by patrickvacek

getifaddrs()is not a portable solution, so if you need to support multiple platforms, you should consider using getaddrinfo, which is POSIX- and Windows-friendly. It is a little more complicated at first glance, but it really isn't that bad. This SO questionhas some good answers and links on the topic. (In particular, the showip.cexample on Beej's pageis quite helpful, and hereis a Windows example; note that it is missing an #include <stdio.h>at the top, and be sure to link against Ws2_32.lib.)

getifaddrs()不是可移植的解决方案,因此如果您需要支持多个平台,您应该考虑使用getaddrinfo,它对 POSIX 和 Windows 友好。乍一看有点复杂,但实际上并没有那么糟糕。这个 SO 问题有一些很好的答案和关于该主题的链接。(特别是,Beej 页面showip.c上的示例非常有用,这里是一个 Windows 示例;请注意,顶部缺少,并确保链接到。)#include <stdio.h>Ws2_32.lib

回答by Steve-o

I've done it here, including a separate version for Wine as the IP version agnostic routines don't current work as expected,

我已经在这里完成了,包括一个单独的 Wine 版本,因为 IP 版本不可知的例程当前没有按预期工作

http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/getifaddrs.c

http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/getifaddrs.c

LGPL 2.1 license

LGPL 2.1 许可证

edit:Wine 1.3 fixes the issues encountered with the IPv4 & IPv6 friendly API.

编辑:Wine 1.3 修复了 IPv4 和 IPv6 友好 API 遇到的问题。

回答by zed_0xff

maybe win32 port of libpcap can help you?

也许libpcap的win32端口可以帮助你?

(or port of libnet, if one exists)

(或 libnet 端口,如果存在)