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 error with udp #3454

Closed
p5pRT opened this issue Feb 20, 2001 · 3 comments
Closed

Net::Ping error with udp #3454

p5pRT opened this issue Feb 20, 2001 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 20, 2001

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

Searchable as RT5871$

@p5pRT
Copy link
Author

p5pRT commented Feb 20, 2001

From anno4000@lublin.zrz.tu-berlin.de

It appears there is a quirk in the behavior of select() with udp
sockets on some systems (Linux, others?). Apparently even when
select() indicates a packet is waiting, subsequent recv() can still
fail with "Connection refused". The discussion at
http​://www.uwsg.iu.edu/hypermail/linux/net/9508.0/0017.html
proves I'm not insane.

In Net​::Ping​::ping_udp() this leads to an error when the undefined
value of $from_saddr is fed into sockaddr_in()​: "Bad arg length
for Socket​::unpack_sockaddr_in..."

The workaround is simple​: Just check $from_saddr for defined-ness and do
nothing if it isn't. The patch below gives the right behavior on my Linux
box, i.e. it times out when udp echo is disallowed and behaves as before
when it's allowed. I haven't tested anything else.

Regards, Anno

Inline Patch
--- Ping.pm	Fri Feb 16 13:09:05 2001
+++ Ping_new.pm	Tue Feb 20 17:46:01 2001
@@ -366,17 +366,19 @@
             $ret = undef;
             $done = 1;
         }
-        elsif ($nfound)         # A packet is waiting
+        elsif ($nfound)         # A packet is probably waiting
         {
             $from_msg = "";
             $from_saddr = recv($self->{"fh"}, $from_msg, 1500, $flags);
-            ($from_port, $from_ip) = sockaddr_in($from_saddr);
-            if (($from_ip eq $ip) &&        # Does the packet check out?
-                ($from_port == $self->{"port_num"}) &&
-                ($from_msg eq $msg))
-            {
-                $ret = 1;       # It's a winner
-                $done = 1;
+            if (defined $from_saddr) { # quirk in select on udp socket
+                ($from_port, $from_ip) = sockaddr_in($from_saddr);
+                if (($from_ip eq $ip) &&        # Does the packet check out?
+                    ($from_port == $self->{"port_num"}) &&
+                    ($from_msg eq $msg))
+                {
+                    $ret = 1;       # It's a winner
+                    $done = 1;
+                }
             }
         }
         else                    # Oops, timed out
@@ -385,7 +387,7 @@
         }
     }
     return($ret);
-}   
+}
 
 # Description:  Close the connection unless we are using the tcp
 # protocol, since it will already be closed.
Perl Info

Flags:
    category=library
    severity=low

Site configuration information for perl v5.6.0:

Configured by anno4000 at Wed Jun  7 10:42:24 MEST 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.0.36, archname=i586-linux
    uname='linux lublin.zrz.tu-berlin.de 2.0.36 #5 fre apr 23 14:43:16 cest 1999 i586 unknown '
    config_args='-de'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.7.2.3
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=/lib/libc-2.0.7.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.0:
    /usr/local/lib/perl5/5.6.0/i586-linux
    /usr/local/lib/perl5/5.6.0
    /usr/local/lib/perl5/site_perl/5.6.0/i586-linux
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.6.0:
    HOME=/opt/home/anno4000
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/X11R6/lib:/usr/local/LessTif/Motif1.2/lib
    LOGDIR (unset)
    PATH=/opt/home/anno4000/bin:/sbin:/usr/local/bin:/bin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/openwin/bin:/usr/games
    PERL_BADLANG (unset)
    PERL_PRIVLIB=/usr/local/lib/perl5/5.6.0
    PERL_SITELIB=/usr/local/lib/perl5/site_perl/5.6.0
    SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Apr 8, 2005

From @smpeters

[anno4000@​lublin.zrz.tu-berlin.de - Tue Feb 20 00​:50​:27 2001]​:

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

It appears there is a quirk in the behavior of select() with udp
sockets on some systems (Linux, others?). Apparently even when
select() indicates a packet is waiting, subsequent recv() can still
fail with "Connection refused". The discussion at
http​://www.uwsg.iu.edu/hypermail/linux/net/9508.0/0017.html
proves I'm not insane.

In Net​::Ping​::ping_udp() this leads to an error when the undefined
value of $from_saddr is fed into sockaddr_in()​: "Bad arg length
for Socket​::unpack_sockaddr_in..."

The workaround is simple​: Just check $from_saddr for defined-ness and
do
nothing if it isn't. The patch below gives the right behavior on my
Linux
box, i.e. it times out when udp echo is disallowed and behaves as
before
when it's allowed. I haven't tested anything else.

Regards, Anno

--- Ping.pm Fri Feb 16 13​:09​:05 2001
+++ Ping_new.pm Tue Feb 20 17​:46​:01 2001
@​@​ -366,17 +366,19 @​@​
$ret = undef;
$done = 1;
}
- elsif ($nfound) # A packet is waiting
+ elsif ($nfound) # A packet is probably waiting
{
$from_msg = "";
$from_saddr = recv($self->{"fh"}, $from_msg, 1500,
$flags);
- ($from_port, $from_ip) = sockaddr_in($from_saddr);
- if (($from_ip eq $ip) && # Does the packet check
out?
- ($from_port == $self->{"port_num"}) &&
- ($from_msg eq $msg))
- {
- $ret = 1; # It's a winner
- $done = 1;
+ if (defined $from_saddr) { # quirk in select on udp
socket
+ ($from_port, $from_ip) = sockaddr_in($from_saddr);
+ if (($from_ip eq $ip) && # Does the packet
check out?
+ ($from_port == $self->{"port_num"}) &&
+ ($from_msg eq $msg))
+ {
+ $ret = 1; # It's a winner
+ $done = 1;
+ }
}
}
else # Oops, timed out
@​@​ -385,7 +387,7 @​@​
}
}
return($ret);
-}
+}

# Description​: Close the connection unless we are using the tcp
# protocol, since it will already be closed.

There have been changes to this code that appear to handle your concerns
without implementing your patch. If this is still a problem, please let
us know.

@p5pRT p5pRT closed this as completed Apr 8, 2005
@p5pRT
Copy link
Author

p5pRT commented Apr 8, 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