Subject: | MS Windows port, missing functionality |
Date: | Thu, 19 Dec 2013 19:17:51 +0100 (CET) |
To: | bug-Socket [...] rt.cpan.org |
From: | Carsten Dehning <carsten.dehning [...] scai.fraunhofer.de> |
Dear Paul Evans,
I am currently extending a multi platform software package (Unix/Linux/Windows, C/C++ and Perl)
from IPv4 to IPv6 (dual stack mode). The C-world is fine since I can easily handle the differences
between the Unix and Windows world.
However there are some issues with the Socket module on the Perl side.
As expected, with MS Windows some POSIX calls are missing in the MS winsock libraries or have at
least different names, e.g.:
inet_ntop() == InetNtopA()
http://msdn.microsoft.com/de-de/library/windows/desktop/cc805843(v=vs.85).aspx
inet_pton() == InetPtonA()
http://msdn.microsoft.com/de-de/library/windows/desktop/cc805844(v=vs.85).aspx
Furthermore these functions became first available under Vista.
My workaround for XP (still some customers :-(() is the use of
WSAStringToAddress()
http://msdn.microsoft.com/de-de/library/windows/desktop/ms742214(v=vs.85).aspx
WSAAddressToString()
http://msdn.microsoft.com/de-de/library/windows/desktop/ms741516(v=vs.85).aspx
Both are available since Window 2000.
In the Perl Socket module the XS functions inet_ntop() and inet_pton() are not implemented for Windows
since the Makefile.PL sub check_for() cannot find them - which is correct and not a bug.
I should mention that I use Active State Perl, version 5.18, which is build with MINGW.
Would it be possible for you to implement these functions also for Windows?
My way in the C-world is e.g (USOCKADDR is a union to wrap IPv6 & IPv4).
#ifdef _WIN32
DWORD len = countof(str);
WSAAddressToStringA(&(usockaddr.saddr),sizeof(USOCKADDR),NULL,str,&len);
#else
inet_ntop(usockaddr.af,&usockaddr,str,sizeof(str));
#endif
I believe a similar #ifdef would be possible in the Socket.xs
#ifdef _WIN32
// addr must have the proper AF assigned
DWORD len = countof(str);
WSAAddressToStringA(&addr,sizeof(addr),NULL,str,&len);
#else
inet_ntop(af, &addr, str, sizeof str);
#endif
The major work then seems to be the modification of the checks in Makefile.PL to account for the
Windows specialities. On the other hand it would be a major advantage for all Perl users to have
platform independent POSIX calls also working under Windows.
Another option would be to add the WSA calls to the Socket.pm (only implemented with the Windows version)
and then I can easily switch between POSIX and the WSA calls inside the Perl code.
Right now I cannot implement IPv6 perl under Windows since both, POSIX and WSA, are missing.
With best regards
Carsten Dehning