Is there an alternative to inet_ntop / InetNtop in

2019-02-07 00:40发布

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.

4条回答
Fickle 薄情
2楼-- · 2019-02-07 01:10

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.

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.

查看更多
该账号已被封号
3楼-- · 2019-02-07 01:12

you can use winsocket with mingw-64 on windows 7

#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)

查看更多
疯言疯语
4楼-- · 2019-02-07 01:25

From the winsock layer: WSAAddressToString (ntop) and WSAStringToAddress (pton)

查看更多
别忘想泡老子
5楼-- · 2019-02-07 01:31

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).

const char * inet_ntop(int af, const void *src, char *dst, size_t size)
查看更多
登录 后发表回答