Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

(tye)Re2: A proposal for improvements to Net::Ping

by tye (Cardinal)
on Mar 10, 2001 at 13:48 UTC ( #63455=note: print w/ replies, xml ) Need Help??


in reply to Re: A proposal for improvements to Net::Ping
in thread A proposal for improvements to Net::Ping

2) I disagree with all of your points. But I think there are enough complexities here "we" should avoid letting it delay other enhancements.

If you don't want non-privileged users to be able to run `ping`, then take it away from them. The reason ping is set-UID is so that non-privileged users can use it and the reason it is an executable and not a library that is that way is because all Unixes have set-UID binaries while many don't have set-UID libraries.

If a user has a trojan `ping` in their $PATH, then that is problem even without a Perl module involved. Just find "ping" in $ENV{PATH} and use it if they request that kind of ping.

A module is the perfect place to collect the heuristics needed to interpret the output of `ping` on different systems. There are already modules that do this for other commands such as `ps`. It makes sense to me to have a Net::Ping::External (since it will get a bit complex) and just have Net::Ping know how to use that module. Perl is very good at heuristics so I don't think this will be a huge problem.

3) As mentioned, this would just use the best method available and wouldn't have to time out multiple times. I'd also make it the default "protocol" so "just doing a ping" usually works without the script writer having to worry about "am I being run as root?", "what operating system is this", etc. Again, a module is a good place to collect these decisions.

4) Non-blocking connect doesn't work under Win32, BTW. The SO_RCVTIMEO sounds interesting. I have my doubts that it works for connect [just based on the name] which is all that we need it for, but it certainly sounds worth looking into. I find it interesting that even Perl's Socket modules use alarm to timeout connect (even when they use other methods for timing out other calls).

5) Well, I wouldn't choose fork for this. For UDP and ICMP you can create a single socket, send out a bunch of packets and see what comes back. For TCP, on systems where non-blocking connect works, you can create a bunch of sockets, start connects on each and use select to wait to see what happens. That is the kind of stuff that makes sense to encapsulate in a module.

        - tye (but my friends call me "Tye")


Comment on (tye)Re2: A proposal for improvements to Net::Ping
Re: (tye)Re2: A proposal for improvements to Net::Ping
by Falkkin (Chaplain) on Mar 10, 2001 at 23:52 UTC
    Your point (2) I agree with... I propose the creation of a new module, Net::Ping::External, to handle the use of the system's ping command. Net::Ping will know how to use the module, through a new protocol called "external", and the "auto" protocol of Net::Ping will skip the "external" protocol if Net::Ping::External is not installed on the system or if Net::Ping::External can't find a suitable ping command. If we could get documentation on what various systems' ping commands return on success/failure, that would be the easiest way to parse the results... otherwise, we'll probably need to use regexes and the like to parse results on a system-by-system basis.

    (3) Yes, you are correct in your interpretation of what I want to do with the "auto" protocol.

    (4) I just found out the hard way that non-blocking connect doesn't work under Win systems. Why is that? Setting SO_RCVTIMEO and/or SO_SNDTIMEO doesn't work, under any OS, AFAIK because no data is actually being sent or received. If the Socket modules use alarm() to implement timeouts, do these timeouts work on non-alarm()-supporting systems (i.e. Windows)? Does anybody have any further ideas on how I can get a TCP ping to timeout on WinXX systems? My only thought at this time is to use Win32::CreateProcess or fork() to spawn a child, and kill it if it's not returned by the time the timeout has passed.

    (5) select() does make perfect sense in this situation. I still think that this is functionality I would rather pull into another new module, Net::Ping::Parallel, instead of adding feature-bloat to the current module.

    This has generated a lot of discussion; I'm wondering if I shouldn't create a Sourceforge account for this project such that there is a central place to store the various advantages/drawbacks to each of the proposed enhancements, and a CVS account so that people can view the current progress (and any interested perlers can contribute code.) Once the code has been mostly "fixed", I'll post it to the code section here for further review. I think the sourceforge page should probably be posted to comp.lang.perl.modules or comp.lang.perl.misc (I frequent neither newsgroup so I don't know offhand which would be most appropriate).

      2) BTW, I'd just bundle Net::Ping::External in with Net::Ping so they are installed together (though making Net::Ping robust in the face of no Net::Ping::External is still a good idea).

      4) As I mention in Net::Ping, the mini series, non-blocking connect not working is simply a bug in WinSock (both 1 and 2). You can use the non-standard Async* APIs to do non-blocking "connect" under Win32, but using Win32::CreateProcess is going to be a lot less work so that is the way I would go for Win32. Switching from alarm to non-blocking connect makes sense for Unixy systems. And no, the Perl Socket modules don't support connect timeouts under Win32 (they detect that alarm is not supported and silently disable the timeout for connect).

      5) Yes, I like the idea of Net::Ping::Parallel but suspect that the code and API will be so similar between Net::Ping and Net::Ping::Parallel, that it makes sense to have them rather tightly interconnected. For example, it might work to teach Net::Ping to support an asynchronous API that Net::Ping::Parallel uses. In the end, whether these are independant modules, interconnected modules, two module that use a third, lower-level module, or even just two name spaces handled by a single module depends on the grimy details when you get to implementing them.

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://63455]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-09-03 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls