BTW, the answer to this (and it was not a trick) question was that the
array elements were backwards, i.e. this is wrong:
$long_current_ip = (@current_ip[0] * 16777216) +
(@current_ip[1] * 65536) + (@current_ip[2] * 256) + @current_ip[3];
and this
$long_current_ip = (@current_ip[3] * 16777216) +
(@current_ip[2] * 65536) + (@current_ip[1] * 256) + @current_ip[0];
and this
$long_current_ip = (@current_ip[3] << 24) + (@current_ip[2] << 16)
+ (@current_ip[1] << 8) + @current_ip[0];
are correct.
Steve
At 04:47 PM 1/19/01 -0600, you wrote:
>Steve Sotis wrote:
> >
> > winsock offers an inet_addr function which converts a dotted IP address to
> > an unsigned long.
> >
> > Is there an equivalent Perl function in any library? A search of
> > ActiveState does not seem to turn up one.
>
>I know that this is not immediately apparent in the Perl docs --
>especially, if you expect to find this via perldoc -f/-q; but, take
>alook at the following:
>
>#! perl.exe -w
>use Socket;
>use strict;
>while (<>) {
> print test_ip($_)
> ? "GOOD: $_\n\n"
> : "BAD: $_\n\n"
>}
>sub test_ip {
> chomp;
> return $_ eq ( join '.', unpack("C*", inet_aton($_)) ) ? 1 : 0;
>}
>exit;
>
>
>If you follow this test for valid ip address, then you can go into
>Socket.pm, &c. and learn that much can be done with inet_aton, inet_ntoa
>and pack.
>
>Hope this helps . . .
>
>--
>
>Best Regards,
>
>mds
>mds resource
>888.250.3987
>
>"Dare to fix things before they break . . . "
>
>"Our capacity for understanding is inversely proportional to how much we
>think we know. The more I know, the more I know I don't know . . . "
>_______________________________________________
>Perl-Win32-Web mailing list
>[EMAIL PROTECTED]
>http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web