Porting getifaddrs to Win XP

末鹿安然 提交于 2019-12-18 05:56:21

问题


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.

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?


回答1:


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




回答2:


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 question has some good answers and links on the topic. (In particular, the showip.c example on Beej's page is quite helpful, and here is a Windows example; note that it is missing an #include <stdio.h> at the top, and be sure to link against Ws2_32.lib.)




回答3:


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

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

LGPL 2.1 license

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




回答4:


maybe win32 port of libpcap can help you?

(or port of libnet, if one exists)



来源:https://stackoverflow.com/questions/3069082/porting-getifaddrs-to-win-xp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!