Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 581
master cheif Avatar asked Oct 13 '09 16:10

master cheif


3 Answers

From the WinSock layer:

  • WSAAddressToString (ntop)
  • WSAStringToAddress (pton)
like image 183
0xdky Avatar answered Oct 01 '22 02:10

0xdky


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.

like image 37
Eclipse Avatar answered Oct 01 '22 04:10

Eclipse


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)
like image 22
Yuriy Petrovskiy Avatar answered Oct 01 '22 04:10

Yuriy Petrovskiy