Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net::Ping icmp failure with Perl 5.8.6 #7733

Closed
p5pRT opened this issue Jan 4, 2005 · 16 comments
Closed

Net::Ping icmp failure with Perl 5.8.6 #7733

p5pRT opened this issue Jan 4, 2005 · 16 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 4, 2005

Migrated from rt.perl.org#33664 (status was 'resolved')

Searchable as RT33664$

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2005

From @spainja

Created by @spainja

The following test script, which works with Perl 5.8.4, fails with Perl
5.8.6​:

use Net​::Ping;
our $p = Net​::Ping->new( 'icmp', 1, 1 );
print $p->ping( '10.1.0.1' ) ? 'alive' : 'unreachable';
$p->close();

The error message is​: icmp socket error - at C​:\PingTest.pl line 2

The test script works normally when the protocol in line 2 is changed
from 'icmp' to 'udp'.

The problem is consistently reproducible on different machines running
Windows XP SP-2 and Windows Server 2003.

Thanks and Happy New Year.

Jeffry A. Spain, CCNP
Network Administrator
Cincinnati Country Day School
6905 Given Road, Cincinnati, OH 45243-2898, USA
Phone +1 (513) 979-0238; Fax +1 (513) 527-7632 (UTC-5)
spainj@​countryday.net

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl v5.8.6:

Configured by ActiveState at Mon Dec 13 09:51:32 2004.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DNO_HASH_SEED
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO
-DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf
-libpath:"C:\Perl\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf  -libpath:"C:\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY
    21540 Fix backward-compatibility issues in if.pm
    23565 Wrong MANIFEST.SKIP


@INC for perl v5.8.6:
    C:/Perl/lib
    C:/Perl/site/lib
    .


Environment for perl v5.8.6:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Python24\.;C:\bin\;C:\Perl\bin\;C:\Program Files\Support
Tools\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA
~1\COMMON~1\Odbc\FILEMA~1;C:\Program Files\SecureCRT\;C:\Program
Files\ActiveState Komodo 3.0\
    PERL_BADLANG (unset)
    SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2005

From @smpeters

On Tue, Jan 04, 2005 at 02​:13​:56AM -0000, Spain, Jeffry A. wrote​:

# New Ticket Created by "Spain, Jeffry A."
# Please include the string​: [perl #33664]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=33664 >

This is a bug report for perl from spainj@​countryday.net,
generated with the help of perlbug 1.35 running under perl v5.8.6.

-----------------------------------------------------------------
[Please enter your report here]

The following test script, which works with Perl 5.8.4, fails with Perl
5.8.6​:

use Net​::Ping;
our $p = Net​::Ping->new( 'icmp', 1, 1 );
print $p->ping( '10.1.0.1' ) ? 'alive' : 'unreachable';
$p->close();

The error message is​: icmp socket error - at C​:\PingTest.pl line 2

The test script works normally when the protocol in line 2 is changed
from 'icmp' to 'udp'.

The problem is consistently reproducible on different machines running
Windows XP SP-2 and Windows Server 2003.

Thanks and Happy New Year.

Jeffry A. Spain, CCNP
Network Administrator
Cincinnati Country Day School
6905 Given Road, Cincinnati, OH 45243-2898, USA
Phone +1 (513) 979-0238; Fax +1 (513) 527-7632 (UTC-5)
spainj@​countryday.net

Are you using the Windows Firewall on Windows XP? The default with the
firewall is to drop all ICMP traffic.

Steve Peters
steve@​fisharerojo.org

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2005

From nick@ing-simmons.net

Jeffry A. Spain <perl5-porters@​perl.org> writes​:

# New Ticket Created by "Spain, Jeffry A."
# Please include the string​: [perl #33664]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=33664 >

This is a bug report for perl from spainj@​countryday.net,
generated with the help of perlbug 1.35 running under perl v5.8.6.

-----------------------------------------------------------------
[Please enter your report here]

The following test script, which works with Perl 5.8.4, fails with Perl
5.8.6​:

use Net​::Ping;
our $p = Net​::Ping->new( 'icmp', 1, 1 );
print $p->ping( '10.1.0.1' ) ? 'alive' : 'unreachable';
$p->close();

The error message is​: icmp socket error - at C​:\PingTest.pl line 2

The test script works normally when the protocol in line 2 is changed
from 'icmp' to 'udp'.

The problem is consistently reproducible on different machines running
Windows XP SP-2 and Windows Server 2003.

On UNIX sending 'icmp' needs root rights which is approximately
equivalent to 'Administrator' rights on Win32.

Does it work when run from an account which has such rights?

Thanks and Happy New Year.

Jeffry A. Spain, CCNP
Network Administrator
Cincinnati Country Day School
6905 Given Road, Cincinnati, OH 45243-2898, USA
Phone +1 (513) 979-0238; Fax +1 (513) 527-7632 (UTC-5)
spainj@​countryday.net

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=high
---
Site configuration information for perl v5.8.6​:

Configured by ActiveState at Mon Dec 13 09​:51​:32 2004.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration​:
Platform​:
osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO
-DPERL_MSVCRT_READFIX',
optimize='-MD -Zi -DNDEBUG -O1',
cppflags='-DWIN32'
ccversion='', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='link', ldflags ='-nologo -nodefaultlib -debug -opt​:ref,icf
-libpath​:"C​:\Perl\lib\CORE" -machine​:x86'
libpth=\lib
libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib msvcrt.lib
perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrt.lib
libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
gnulibc_version='undef'
Dynamic Linking​:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt​:ref,icf -libpath​:"C​:\Perl\lib\CORE" -machine​:x86'

Locally applied patches​:
ACTIVEPERL_LOCAL_PATCHES_ENTRY
21540 Fix backward-compatibility issues in if.pm
23565 Wrong MANIFEST.SKIP

---
@​INC for perl v5.8.6​:
C​:/Perl/lib
C​:/Perl/site/lib
.

---
Environment for perl v5.8.6​:
HOME (unset)
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C​:\Python24\.;C​:\bin\;C​:\Perl\bin\;C​:\Program Files\Support
Tools\;C​:\WINDOWS\system32;C​:\WINDOWS;C​:\WINDOWS\System32\Wbem;C​:\PROGRA
1\COMMON1\Odbc\FILEMA~1;C​:\Program Files\SecureCRT\;C​:\Program
Files\ActiveState Komodo 3.0\
PERL_BADLANG (unset)
SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2005

From @spainja

Thanks. I'm running from local administrator accounts that have full
rights on the machines tested. I am able to send command line pings and
successfully receive echo replies in each case. Uninstalling Perl 5.8.6
and reinstalling Perl 5.8.4 makes the test script work.

-----Original Message-----
From​: Nick Ing-Simmons via RT [mailto​:perlbug-followup@​perl.org]
Sent​: Tuesday, January 04, 2005 8​:46 AM
To​: Spain, Jeffry A.
Subject​: Re​: [perl #33664] Net​::Ping icmp failure with Perl 5.8.6

Jeffry A. Spain <perl5-porters@​perl.org> writes​:

# New Ticket Created by "Spain, Jeffry A."
# Please include the string​: [perl #33664]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=33664 >

This is a bug report for perl from spainj@​countryday.net,
generated with the help of perlbug 1.35 running under perl v5.8.6.

-----------------------------------------------------------------
[Please enter your report here]

The following test script, which works with Perl 5.8.4, fails with Perl
5.8.6​:

use Net​::Ping;
our $p = Net​::Ping->new( 'icmp', 1, 1 );
print $p->ping( '10.1.0.1' ) ? 'alive' : 'unreachable';
$p->close();

The error message is​: icmp socket error - at C​:\PingTest.pl line 2

The test script works normally when the protocol in line 2 is changed
from 'icmp' to 'udp'.

The problem is consistently reproducible on different machines running
Windows XP SP-2 and Windows Server 2003.

On UNIX sending 'icmp' needs root rights which is approximately
equivalent to 'Administrator' rights on Win32.

Does it work when run from an account which has such rights?

Thanks and Happy New Year.

Jeffry A. Spain, CCNP
Network Administrator
Cincinnati Country Day School
6905 Given Road, Cincinnati, OH 45243-2898, USA
Phone +1 (513) 979-0238; Fax +1 (513) 527-7632 (UTC-5)
spainj@​countryday.net

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=high
---
Site configuration information for perl v5.8.6​:

Configured by ActiveState at Mon Dec 13 09​:51​:32 2004.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration​:
Platform​:
osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO
-DPERL_MSVCRT_READFIX',
optimize='-MD -Zi -DNDEBUG -O1',
cppflags='-DWIN32'
ccversion='', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='__int64',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='link', ldflags ='-nologo -nodefaultlib -debug -opt​:ref,icf
-libpath​:"C​:\Perl\lib\CORE" -machine​:x86'
libpth=\lib
libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib msvcrt.lib
perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrt.lib
libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
gnulibc_version='undef'
Dynamic Linking​:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt​:ref,icf -libpath​:"C​:\Perl\lib\CORE" -machine​:x86'

Locally applied patches​:
ACTIVEPERL_LOCAL_PATCHES_ENTRY
21540 Fix backward-compatibility issues in if.pm
23565 Wrong MANIFEST.SKIP

---
@​INC for perl v5.8.6​:
C​:/Perl/lib
C​:/Perl/site/lib
.

---
Environment for perl v5.8.6​:
HOME (unset)
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C​:\Python24\.;C​:\bin\;C​:\Perl\bin\;C​:\Program Files\Support
Tools\;C​:\WINDOWS\system32;C​:\WINDOWS;C​:\WINDOWS\System32\Wbem;C​:\PROGR
A
1\COMMON1\Odbc\FILEMA~1;C​:\Program Files\SecureCRT\;C​:\Program
Files\ActiveState Komodo 3.0\
PERL_BADLANG (unset)
SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2005

From @spainja

Thank you, Steve. I can reproduce the problem with the Windows firewall
disabled. Even with the firewall enabled, the script works with Perl
5.8.4 and fails with 5.8.6. It also fails with 5.8.6 on Windows Server
2003, where there is no firewall.

The error message arises from the Ping.pm module, lines 148 and 149​:
  socket($self->{"fh"}, PF_INET, SOCK_RAW, $self->{"proto_num"}) ||
  croak("icmp socket error - $!");

There has been no change to the Ping.pm Perl code between versions 5.8.4
and 5.8.6.

I'd be happy to help with further troubleshooting. Please let me know
what you would like me to do. Thanks. Jeff.

-----Original Message-----
From​: Steve Peters via RT [mailto​:perlbug-followup@​perl.org]
Sent​: Tuesday, January 04, 2005 8​:23 AM
To​: Spain, Jeffry A.
Subject​: Re​: [perl #33664] Net​::Ping icmp failure with Perl 5.8.6

On Tue, Jan 04, 2005 at 02​:13​:56AM -0000, Spain, Jeffry A. wrote​:

# New Ticket Created by "Spain, Jeffry A."
# Please include the string​: [perl #33664]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=33664 >

This is a bug report for perl from spainj@​countryday.net,
generated with the help of perlbug 1.35 running under perl v5.8.6.

-----------------------------------------------------------------
[Please enter your report here]

The following test script, which works with Perl 5.8.4, fails with
Perl
5.8.6​:

use Net​::Ping;
our $p = Net​::Ping->new( 'icmp', 1, 1 );
print $p->ping( '10.1.0.1' ) ? 'alive' : 'unreachable';
$p->close();

The error message is​: icmp socket error - at C​:\PingTest.pl line 2

The test script works normally when the protocol in line 2 is changed
from 'icmp' to 'udp'.

The problem is consistently reproducible on different machines running
Windows XP SP-2 and Windows Server 2003.

Thanks and Happy New Year.

Jeffry A. Spain, CCNP
Network Administrator
Cincinnati Country Day School
6905 Given Road, Cincinnati, OH 45243-2898, USA
Phone +1 (513) 979-0238; Fax +1 (513) 527-7632 (UTC-5)
spainj@​countryday.net

Are you using the Windows Firewall on Windows XP? The default with the
firewall is to drop all ICMP traffic.

Steve Peters
steve@​fisharerojo.org

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2005

From @spainja

I have refined the test script as follows to further isolate the error​:

use Socket qw( PF_INET SOCK_RAW );
socket( S, PF_INET, SOCK_RAW, 1 )
  ? warn "icmp socket ok\n"
  : die "icmp socket error - $!\n";

I downloaded and compiled the Perl source for 5.8.5, 5.8.6, and 5.9.1
using Visual Studio .NET 2003 on Windows XP SP-2. I am logged in as a
local administrator and the Windows Firewall is disabled. The icmp
socket is ok for 5.8.5 and 5.9.1. The error occurs only with 5.8.6 and
$! is an empty string.

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2005

From @spainja

I have further localized the problem to the file \perl-5.8.6\win32
\win32sck.c. Perl 5.8.6 uses Windows Sockets version 2, as opposed to
Perl 5.8.5 and earlier, which use Windows Sockets version 1.1. Herein
lies the issue.

In Perl 5.8.6, win32sck.c, starting in line 406, defines the function
open_ifs_sockets, which uses the function WSCEnumProtocols (see
http​://msdn.microsoft.com/library/default.asp?url=/library/en-
us/winsock/winsock/wscenumprotocols_2.asp) to get information about
the network protocols available on the local machine.

On the machines I tested running Windows 2000 Server SP-4, Windows
Server 2003, and Windows XP SP-2, WSCEnumProtocols returns among
others, three different protocols in the AF_INET family. These are TCP
(protocol 6, type SOCK_STREAM), UDP (protocol 17, type SOCK_DGRAM),
and raw IP (protocol 0, type SOCK_RAW). ICMP (protocol 1) isn't among
the available options, and this dooms Net​::Ping.pm to failure when it
tries to open an "ICMP" socket.

Since Net​::Ping.pm constructs its own raw IP packets for ICMP pings, I
suspect it may work with a raw IP socket (protocol 0, type SOCK_RAW),
which is one of the available types. Making this modification to
Ping.pm will be my next step.

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2005

From @spainja

Based on further testing it is apparent that when data returned by the
WSCEnumProtocols function indicates that type SOCK_RAW is available
for a particular address family, then the Socket function can create a
socket for that family of type SOCK_RAW for any protocol.

I modified the open_ifs_sockets function in \perl-5.8.6\win32
\win32sck.c to allow for this. With the revised code, Net​::Ping now
works with the ICMP protocol.

The attached diff file will patch win32sck.c with the proposed
revisions.

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2005

From @spainja

win32sck.c.diff
422a423,425
>         int protocol_matched = 0;
>         int i;
>         WSAPROTOCOL_INFOA proto_info;
430d432
<             int i;
433,439d434
<                 WSAPROTOCOL_INFOA proto_info;
< 
<                 if ((af != AF_UNSPEC && af != proto_buffers[i].iAddressFamily)
<                     || (type != proto_buffers[i].iSocketType)
<                     || (protocol != 0 && protocol != proto_buffers[i].iProtocol))
<                     continue;
< 
443c438,445
<                 convert_proto_info_w2a(&(proto_buffers[i]), &proto_info);
---
>                 /* If raw sockets are available for this address family, then
>                  * allow the creation of a raw socket for any protocol */
>                 if (af != AF_UNSPEC && af == proto_buffers[i].iAddressFamily
>                     && type == SOCK_RAW && type == proto_buffers[i].iSocketType)
>                 {
>                     protocol_matched = 1;
>                     break;
>                 }
445c447,453
<                 out = WSASocket(af, type, protocol, &proto_info, 0, 0);
---
>                 /* Otherwise the family, type, and protocol must all match
>                  * what is available */
>                 if (af != AF_UNSPEC && af == proto_buffers[i].iAddressFamily
>                     && type == proto_buffers[i].iSocketType
>                     && protocol != 0 && protocol == proto_buffers[i].iProtocol)
>                 {
>                     protocol_matched = 1;
448a457,463
>         }
> 
>         if (protocol_matched)
>         {
>             convert_proto_info_w2a(&(proto_buffers[i]), &proto_info);
>             out = WSASocket(af, type, protocol, &proto_info, 0, 0);
>         }

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2005

From @spainja

With additional use, I found that the previously revised win32sck.c
code caused the Net​::Telnet module to fail. From correspondence with
this module's author, Jay Rogers <jay@​rgrs.com>, I learned that it is
a common UNIX socket programming convention to call the socket
function with the type set to SOCK_STREAM and the protocol set to
zero. This is shorthand for TCP. Similarly, type SOCK_DGRAM and
protocol zero is shorthand for UDP. This saves the programmer the
trouble of calling getprotobyname("tcp") or getprotobyname("udp") to
resolve the actual protocol number. I added code to win32sck.c to
correctly handle these shortcuts. With this additional code the
Net​::Telnet module works correctly again. No doubt other modules using
Socket.pm would be similarly affected, although I have not done
additional testing at this point. See the attached win32sck.c.diff.2
to patch the original win32sck.c from Perl 5.8.6 with all revisions to
date.

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2005

From @spainja

414a415,438

/\* Allow for the commonly used UNIX shortcuts where TCP is specified as
 \* type SOCK\_STREAM with protocol zero\, and UDP as type SOCK\_DGRAM with
 \* protocol zero\. Change the protocol number from zero to the appropriate
 \* integer value in these cases\. \*/
if \(\!protocol\)
\{
    struct protoent \*pe;
    if \(type == SOCK\_STREAM\)
    \{
        if \(pe = win32\_getprotobyname\("tcp"\)\)
            protocol = pe\->p\_proto;
        else
            return out;
    \}
    else
    if \(type == SOCK\_DGRAM\)
    \{
        if \(pe = win32\_getprotobyname\("udp"\)\)
            protocol = pe\->p\_proto;
        else
            return out;
    \}
\}

422a447,449

    int protocol\_matched = 0;
    int i;
    WSAPROTOCOL\_INFOA proto\_info;

430d456
< int i;
433,439d458
< WSAPROTOCOL_INFOA proto_info;
<
< if ((af != AF_UNSPEC && af != proto_buffers[i].iAddressFamily)
< || (type != proto_buffers[i].iSocketType)
< || (protocol != 0 && protocol != proto_buffers[i].iProtocol))
< continue;
<
443c462,469
< convert_proto_info_w2a(&(proto_buffers[i]), &proto_info);


            /\* If raw sockets are available for this address family\, then
             \* allow the creation of a raw socket for any protocol \*/
            if \(af \!= AF\_UNSPEC && af == proto\_buffers\[i\]\.iAddressFamily
                && type == SOCK\_RAW && type == proto\_buffers\[i\]\.iSocketType\)
            \{
                protocol\_matched = 1;
                break;
            \}

445c471,477
< out = WSASocket(af, type, protocol, &proto_info, 0, 0);


            /\* Otherwise the family\, type\, and protocol must all match
             \* what is available \*/
            if \(af \!= AF\_UNSPEC && af == proto\_buffers\[i\]\.iAddressFamily
                && type == proto\_buffers\[i\]\.iSocketType
                && protocol \!= 0 && protocol == proto\_buffers\[i\]\.iProtocol\)
            \{
                protocol\_matched = 1;

448a481,487

    \}

    if \(protocol\_matched\)
    \{
        convert\_proto\_info\_w2a\(&\(proto\_buffers\[i\]\)\, &proto\_info\);
        out = WSASocket\(af\, type\, protocol\, &proto\_info\, 0\, 0\);
    \}

@p5pRT
Copy link
Author

p5pRT commented Apr 18, 2005

From @steve-m-hay

Thank you for the bug report.

I've just committed a change (24242) to bleadperl which I believe should
fix your problem.

The code in 5.8.6 currently obtains a list of transport providers and
checks if the requested af/type/protocol match any of them, with two
exceptions​: if the "af" is given as AF_UNSPEC then the check that "af"
matches is skipped, and if "protocol" is given as 0 then the check that
"protocol" matches is skipped.

Your original patch broke Net-Telnet because you effectively removed the
skipping of the "protocol" check when protocol == 0​: your code will
only ever set protocol_matched if the "protocol" actually does match, or
if "type" is SOCK_RAW.

Likewise, there is another problem with your patch (even the revised
version)​: you have also removed the skipping of the "af" check when af
== AF_UNSPEC​: again, your code will never set protocol_matched if "af"
is AF_UNSPEC.

The change that I have committed is rather simpler than your patches​: I
have simply extended the skipping of the "protocol" check to cover the
case where proto_buffers[i].iProtocol == 0 as well as the case where
protocol == 0.

With this change in place, the test script in your original bug report
now works, and Net-Telnet's test script also still works.

Hopefully this change will make it into the next "stable" release of
perl (5.8.7), which should be quite soon now. In the meantime, you can
also get things working under 5.8.6 by simply setting the environment
variable PERL_ALLOW_NON_IFS_LSP to 1, which skips the WSCEnumProtocols()
call altogether and just does a straight-forward WSASocket() call with
the requested parameters, a la 5.8.5 and earlier.

- Steve

@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2005

From @spainja

Thanks for fixing this problem. Regards, Jeff.

-----Original Message-----
From​: Steve Hay via RT [mailto​:perlbug-followup@​perl.org]
Sent​: Monday, April 18, 2005 12​:33 PM
To​: Spain, Jeffry A.
Subject​: [perl #33664] Net​::Ping icmp failure with Perl 5.8.6

Thank you for the bug report.

I've just committed a change (24242) to bleadperl which I believe should
fix your problem.

The code in 5.8.6 currently obtains a list of transport providers and
checks if the requested af/type/protocol match any of them, with two
exceptions​: if the "af" is given as AF_UNSPEC then the check that "af"
matches is skipped, and if "protocol" is given as 0 then the check that
"protocol" matches is skipped.

Your original patch broke Net-Telnet because you effectively removed the
skipping of the "protocol" check when protocol == 0​: your code will
only ever set protocol_matched if the "protocol" actually does match, or
if "type" is SOCK_RAW.

Likewise, there is another problem with your patch (even the revised
version)​: you have also removed the skipping of the "af" check when af
== AF_UNSPEC​: again, your code will never set protocol_matched if "af"
is AF_UNSPEC.

The change that I have committed is rather simpler than your patches​: I
have simply extended the skipping of the "protocol" check to cover the
case where proto_buffers[i].iProtocol == 0 as well as the case where
protocol == 0.

With this change in place, the test script in your original bug report
now works, and Net-Telnet's test script also still works.

Hopefully this change will make it into the next "stable" release of
perl (5.8.7), which should be quite soon now. In the meantime, you can
also get things working under 5.8.6 by simply setting the environment
variable PERL_ALLOW_NON_IFS_LSP to 1, which skips the WSCEnumProtocols()
call altogether and just does a straight-forward WSASocket() call with
the requested parameters, a la 5.8.5 and earlier.

- Steve

@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2005

From @smpeters

[jaspain - Wed Apr 20 00​:14​:02 2005]​:

Thanks for fixing this problem. Regards, Jeff.

As this problem has been resolved, this ticket will be closed.

@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2005

@smpeters - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant