Is there an alternative to inet_ntop / InetNtop in Windows XP?

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.

13.10.2009 16:44:51
inet_ntop is also missing in Winsock implementation on Windows Phone 8.1. How MS could hope for a success of such a crippled platform?
Ales Teska 7.08.2017 20:53:11

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.

13.10.2009 18:52:12
inet_ntoa is available on every version of windows with WinSock2 on it, you can't trust MSDN when it comes to minimum version, they seem to have forgotten about Win9x and NT4
Anders 15.10.2009 14:42:12
MinGW headers don't contain a declaration of inet_ntop. So even on Windows Vista and later you can't use it :(
Youda008 4.12.2016 11:33:41

From the WinSock layer:

6.11.2019 08:29:45
Note that WSAAddressToString will append the port number as well if your address structure has one. So to just get the IP, you may have to create a new address with no port.
jowo 13.01.2012 08:40:48

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)
7.06.2013 09:46:40

you can use winsocket with mingw-64 on windows 7

#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>


gcc showip.c -lws2_32

Target: x86_64-w64-mingw32 Thread model: win32 gcc version 6.3.0 (GCC)

5.04.2017 16:34:12