While trying to port code from our Enterprise server to one of our Blade workstations, I was working through changing directory pointers and so forth. One of the problems I encountered was a problem with Net::Ping, in that I kept getting an error saying “Can’t get tcp protocol by name” or “Can’t get udp protocol by name” depending on which method I was using. I was able ping on the command line to the destination, but still unable to make the code work. The portion of the code was easily tracked down to a part of the Net::Ping module that reads like this:

elsif ($self->{“proto”} eq “tcp”) { $self->{“proto_num”} = (getprotobyname(‘tcp’))[2] || croak(“Can’t get tcp protocol by name”); $self->{“port_num”} = (getservbyname(‘echo’, ‘tcp’))[2] || croak(“Can’t get tcp protocol by name”); $self->{“fh”} = FileHandle->new(); }

I was able to tweak this module a little bit, with pretty good results, as I was able to go back to the original code I was using with minimal porting. It now looks something like this:

elsif ($self->{“proto”} eq “tcp”) { $self->{“proto_num”} = (getprotobyname(‘tcp’))[2]; # || # croak(“Can’t get tcp protocol by name”); $self->{“port_num”} = (getservbyname(‘echo’, ‘tcp’))[2]; # || # croak(“Can’t get tcp protocol by name”); $self->{“fh”} = FileHandle->new(); }

By forcing the module to continue instead of “croak”ing, I was able to let it complete and get the comeback that it needed to succeed. I also changed (earlier in the module) the max timeout value. This is important because the code I am using has to go out and check over 125 workstations. If some of them are dead, the timeout multiplies fast. I was able to use Shell.pm and run it through the command line from within the program, but the time minimum timeout value allowed is one second, so the other day when all of our workstations were down due to an impending power outage, it took forever for that part of the code to run. Using Net::Ping seems to run much faster.

My questions are these to anyone who might be a little bit more experienced than I:

What, if anything, might this break if left this way, and why would this cause a problem in the first place? Since I am using 5.6.0, was this problem fixed with 5.8 (or newer)? Is this a know problem or am I just hosed (no I’m not from Canada)?

Any thoughts would be appreciated.
PS: Sorry for the book.


In reply to Net::Ping Problems by Paulster2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.