atreyu has asked for the wisdom of the Perl Monks concerning the following question:

UPDATE:
I'd still like to solve this problem, but I have a work-around which I figured I'd post, in case others are helped by this. Taking VinsWorldcom's advice, I modified the Address.pm file to not call Socket. Instead, it calls the ip_to_int function in IP::Tools. Here's the modified sub in Address.pm:

sub new_from_string { my $class = shift; my %p = @_; my $str = delete $p{string}; my $version = delete $p{version}; my $ip = $str; use IP::Tools; # if ( defined $str && inet_pton( AF_INET, $str ) ) { if ( defined $str ) { $version ||= 4; $str = '::' . $str if $version == 6; } else { $version ||= 6; _validate_ip_string( $str, $version ); } return $class->new( _integer => IP::Tools::ip_to_int($ip), # _integer => _string_address_to_integer( $str, $version ), version => $version, %p, ); }

Hi,

I have GeoIP2 running great on Linux, but I can't get it running under *Windows Perl due to errors related to the 'inet_pton' function.

The GeoIP2 module calls MaxMind::DB::Reader (documentation forthcoming), which in turn calls Net::Works::Address, which in turn calls Socket::inet_pton. Once it hits that function, it craps out. Here's some example code:

#!c:/apps/strawberry/perl/bin/perl.exe use strict; use warnings; use Net::Works::Address; my $addr = '1.2.3.4'; my $ip = Net::Works::Address->new_from_string( string => $addr); for(qw/as_string as_integer as_binary as_bit_string version mask_lengt +h/){ print $_,": ",$ip->$_(),"\n"; }
When I run the above code sample, it produces:
Socket::inet_pton not implemented on this architecture at C:/apps/stra +wberry/perl/site/lib/Net/Works/Util.pm line 42.

I've found this Strawberry Perl bug report for it, but it doesn't help, as far as I can see.

From what I can gather at this Stackoverflow discussion, 'inet_pton' was not added to Windows until Vista came around, but there exists in Windows XP a function called WWSAAddressToString() which could be implemented to emulate it. I would not know where to start with that, plus I would prefer a pure Perl solution.

Does anyone have any ideas or pointers?

* Strawberry Perl 5.16.3.1 64-bit on Windows XP Pro, SP2, 64-bit

Replies are listed 'Best First'.
Re: inet_pton on Windows Perl
by VinsWorldcom (Prior) on Aug 14, 2013 at 23:49 UTC

    I've seen this issue too. Even on Windows 7 which has the libraries to compile, the GCC headers and libraries don't have the proper definitions to get it to work.

    My workaround is to recompile the Socket module as per http://vinsworldcom.blogspot.com/2012/08/ipv6-in-perl-on-windows_20.html.

    Of course, this may not work for Windows XP which you're running since ws2_32.dll won't have the inet_pton() function full stop. The other alternative may be to install Socket6 and Socket6::GetAddrInfo and do a little rewrite of the Net::Works::Address module to use Socket6.

      the GCC headers and libraries don't have the proper definitions to get it to work

      It's the same with the compilers provided by mingw.org (not the same vendor that provides the compilers used by Strawberry Perl).

      Are either of these vendors aware of this deficiency ? (There are legal considerations involved in publicly providing headers for MS functions. I think they're supposed to be derived from documentation that MS has made public ... I'm not sure of the exact constraints.)

      Cheers,
      Rob
      Thanks for sharing your solution and suggestions, VinsWorldcom, I'll look into them.

      Also, I guess I should have mentioned that I also tried ActivePerl (5.14) and its built-in toolchain (gcc 3.4.5), as well as the latest MinGW toolchain (gcc 4.7.2), to no avail. Those combinations would fail to even build Math::Int128.

        Those combinations would fail to even build Math::Int128

        For Math::Int128 you need a 64-bit compiler, and hence a 64-bit build of perl.
        Even then, the build is failing due to a bug in either perl itself or the Math-Int128-0.12 source. (Last I heard, the Math::Int128 author was investigating.)

        If you have a 64-bit build of Windows perl you can install Math-Int128-0.12 using ppm:
        ppm install http://www.sisyphusion.tk/ppm/Math-Int128.ppd --force
        That package was built using this patch. (If you want to build Math-Int128-0.12 from source yourself, use that patch in preference to the patch supplied in the afore mentioned bug report.)

        And keep an eye out for Math-Int128-0.13 which will hopefully build straight out of the box with MinGW ports of 64-bit gcc.

        Cheers,
        Rob

      My workaround is to recompile the Socket module as per http://vinsworldcom.blogspot.com/2012/08/ipv6-in-perl-on-windows_20.html.

      Of course, this may not work for Windows XP which you're running since ws2_32.dll won't have the inet_pton() function full stop.

      I went ahead and proved that your guess was right - this did not work on Windows XP. When I get to dmake test I get a Windows dialogue error:

      The procedure entry point inet_ntop could not be located in the dynamic link library WS2_32.dll

      I've come across this suggestion to create wrappers for the two missing functions. I don't know what to do with these...could they be implemented in your ws2tcpip-win.h header file and put into that new dll that your dlltool command creates?