Windows XP 中是否有 inet_ntop / InetNtop 的替代方案?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1561469/
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
Is there an alternative to inet_ntop / InetNtop in Windows XP?
提问by master cheif
I'm trying to compile beej's guide to network programming examples, but Windows XP doesn't have such a function. I'm using mingw, if it makes any difference.
我正在尝试编译 beej 的网络编程示例指南,但 Windows XP 没有这样的功能。我正在使用 mingw,如果它有什么不同的话。
采纳答案by Eclipse
If you're only dealing with IPv4 addresses, you can use inet_ntoa
. It's available on Windows 2000 or later. Otherwise you'll have to either require Vista and later, or write your own inet_ntop function.
如果您只处理 IPv4 地址,则可以使用inet_ntoa
. 它在 Windows 2000 或更高版本上可用。否则,您必须要么需要 Vista 及更高版本,要么编写您自己的 inet_ntop 函数。
You could also look at boost - the boost::asio has an inet_ntop
implementation that works in Windows: boost::asio::detail::socket_ops::inet_ntop
. You can see the source code here.
您还可以看看升压-升压:: ASIO有一个inet_ntop
实现,它在Windows的作品:boost::asio::detail::socket_ops::inet_ntop
。您可以在此处查看源代码。
回答by hackworks
From the WinSock layer:
从 WinSock 层:
WSAAddressToString
(ntop)WSAStringToAddress
(pton)
WSAAddressToString
(ntop)WSAStringToAddress
(质子)
回答by Yuriy Petrovskiy
There is also inet_ntop
function in POSIX compliant libc for Windows (PlibC)library that was created for porting POSIX applications to Windows. There is no notes about it in online documentation, but it exists in file inet_ntop.c
at least since 2008 (according to file date).
POSIX 兼容的 libc for Windows (PlibC)库中还有一个inet_ntop
函数,它是为将 POSIX 应用程序移植到 Windows 而创建的。在线文档中没有关于它的注释,但它至少从 2008 年开始就存在于文件中(根据文件日期)。inet_ntop.c
const char * inet_ntop(int af, const void *src, char *dst, size_t size)
回答by DrMD
you can use winsocket with mingw-64 on windows 7
您可以在 Windows 7 上使用带有 mingw-64 的 winsocket
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
linkwith
链接
gcc showip.c -lws2_32
Target: x86_64-w64-mingw32 Thread model: win32 gcc version 6.3.0 (GCC)
目标:x86_64-w64-mingw32 线程模型:win32 gcc version 6.3.0 (GCC)