Subject: | MS Windows port, missing functionality |
Date: | Thu, 19 Dec 2013 18:19:16 +0100 (CET) |
To: | bug-IO-Socket-IP [...] 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() == InetNtop()
http://msdn.microsoft.com/de-de/library/windows/desktop/cc805843(v=vs.85).aspx
inet_pton() == InetPton()
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.
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