cvs: pear /Net_Ping Ping.php package.xml
| From: | Jan Lehnardt | Date: | Wed, 05 Feb 2003 11:34:31 +0000 |
| Subject: | cvs: pear /Net_Ping Ping.php package.xml | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8718@lists.php.net to get a copy of this message | ||
jan Wed Feb 5 06:34:31 2003 EDT
Modified files:
/pear/Net_Ping Ping.php package.xml
Log:
- introduce PEAR error handling
- add a result object that makes the ping result values easily accessable
- release preparation
#added myself as author. I hope this is fine with Martin.
Index: pear/Net_Ping/Ping.php diff -u pear/Net_Ping/Ping.php:1.20 pear/Net_Ping/Ping.php:1.21 --- pear/Net_Ping/Ping.php:1.20 Sat Jan 4 06:55:51 2003 +++ pear/Net_Ping/Ping.php Wed Feb 5 06:34:30 2003 @@ -19,18 +19,26 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Ping.php,v 1.20 2003/01/04 11:55:51 mj Exp $ +// $Id: Ping.php,v 1.21 2003/02/05 11:34:30 jan Exp $ require_once "PEAR.php"; require_once "OS/Guess.php"; -define('PING_FAILED', 'execution of ping failed'); -define('PING_HOST_NOT_FOUND', 'unknown host'); -define('PING_INVALID_ARGUMENTS', 'invalid argument array'); +define('PING_FAILED_MSG', 'execution of ping failed'); +define('PING_HOST_NOT_FOUND_MSG', 'unknown host'); +define('PING_INVALID_ARGUMENTS_MSG', 'invalid argument array'); +define('PING_CANT_LOCATE_PING_BINARY_MSG', 'unable to locate the ping binary'); +define('PING_RESULT_UNSUPPORTED_BACKEND_MSG', 'Backend not Supported'); + +define('PING_FAILED', 0); +define('PING_HOST_NOT_FOUND', 1); +define('PING_INVALID_ARGUMENTS', 2); +define('PING_CANT_LOCATE_PING_BINARY', 3); +define('PING_RESULT_UNSUPPORTED_BACKEND', 4); /**************************TODO*******************************************/ /* -return an object with ping results, make raw, ping data optional + */ /** @@ -40,23 +48,22 @@ * * <?php * require_once "Net_Ping/Ping.php"; -* $ping = new Net_Ping; -* $ping->setArgs(array("count" => 5), -* "size" => 32), -* "ttl" => 512) -* ) -* ); -* var_dump($ping->ping("example.com")); +* $ping = Net_Ping::factory(); +* if(PEAR::isError($ping)) { +* echo $ping->getMessage(); +* } else { +* $ping->setArgs(array('count' => 2)); +* var_dump($ping->ping('example.com')); +* } * ?> * -* @author Martin Jansen <mj@php.net> -* @version $Revision: 1.20 $ +* @author Jan Lehnardt <jan@php.net> +* @version $Revision: 1.21 $ * @package Net * @access public */ class Net_Ping { - /** * Location where the ping program is stored * @@ -113,22 +120,37 @@ */ var $_argRelation = array(); - /** * Constructor for the Class * * @access private */ - function Net_Ping() + function Net_Ping($ping_path, $sysname) { - $this->_OS_Guess = new OS_Guess; - $this->_sysname = $this->_OS_Guess->getSysname(); - - $this->_setPingPath(); + $this->_ping_path = $ping_path; + $this->_sysname = $sysname; $this->_initArgRelation(); } /** + * Factory for Net_Ping + * + * @access public + */ + function factory() + { + $OS_Guess = new OS_Guess; + $sysname = $OS_Guess->getSysname(); + $ping_path = ''; + + if (($ping_path = Net_Ping::_setPingPath($sysname)) == PING_CANT_LOCATE_PING_BINARY) { + return PEAR::throwError(PING_CANT_LOCATE_PING_BINARY_MSG, PING_CANT_LOCATE_PING_BINARY); + } else { + return new Net_Ping($ping_path, $sysname); + } + + } + /** * Set the arguments array * * @param array $args Hash with options @@ -138,7 +160,7 @@ function setArgs($args) { if (!is_array($args)) { - return PEAR::raiseError(PING_INVALID_ARGUMENTS); + return PEAR::throwError(PING_INVALID_ARGUMENTS_MSG, PING_INVALID_ARGUMENTS); } /* accept empty arrays, but set flag*/ @@ -158,12 +180,21 @@ * * @access private */ - function _setPingPath() + function _setPingPath($sysname) { - if ("windows" == $this->_sysname) { - $this->_ping_path = "ping"; + $status = ''; + $output = array(); + $ping_path = ''; + + if ("windows" == $sysname) { + return "ping"; } else { - $this->_ping_path = exec("which ping"); /* FIXME: windows */ + $ping_path = exec("which ping", $output, $status); + if (0 != $status) { + return PING_CANT_LOCATE_PING_BINARY; + } else { + return $ping_path; + } } } @@ -254,13 +285,13 @@ exec($cmd, $this->_result); if (!is_array($this->_result)) { - return PING_FAILED; + return PEAR::throwError(PING_FAILED_MSG, PING_FAILED); } if (count($this->_result) == 0) { - return PING_HOST_NOT_FOUND; + return PEAR::throwError(PING_HOST_NOT_FOUND_MSG, PING_HOST_NOT_FOUND); } else { - return $this->_result; + return Net_Ping_Result::factory($this->_result, $this->_sysname); } } @@ -282,7 +313,7 @@ ) ); $res = $this->ping($host); - if ($res == PING_HOST_NOT_FOUND) { + if (PEAR::isError($res)) { return false; } if (!preg_match_all('|\d+|', $res[3], $m) || count($m[0]) < 3) { @@ -381,5 +412,333 @@ } +} + + +/** +* Container class for Net_Ping results +* +* @author Jan Lehnardt <jan@php.net> +* @version $Revision: 1.21 $ +* @package Net +* @access private +*/ +class Net_Ping_Result +{ + /** + * ICMP sequence number and associated time in ms + * + * @var array + * @access private + */ + var $_icmp_sequence = array(); /* array($sequence_number => $time ) */ + + /** + * The target's IP Address + * + * @var string + * @access private + */ + var $_target_ip; + + /** + * Number of bytes that are sent with each ICMP request + * + * @var int + * @access private + */ + var $_bytes_per_request; + + /** + * The total number of bytes that are sent with all ICMP requests + * + * @var int + * @access private + */ + var $_bytes_total; + + /** + * The ICMP request's TTL + * + * @var int + * @access private + */ + var $_ttl; + + /** + * The raw Net_Ping::result + * + * @var array + * @access private + */ + var $_raw_data = array(); + + /** + * The Net_Ping::_sysname + * + * @var int + * @access private + */ + var $_sysname; + + /** + * Statistical information about the ping + * + * @var int + * @access private + */ + var $_round_trip = array(); /* array('min' => xxx, 'avg' => yyy, 'max' => zzz) */ + + + /** + * Constructor for the Class + * + * @access private + */ + function Net_Ping_Result($result, $sysname) + { + $this->_raw_data = $result; + $this->_sysname = $sysname; + + $this->_parseResult(); + } + + /** + * Factory for Net_Ping_Result + * + * @access public + * @param array $result Net_Ping result + * @param string $sysname OS_Guess::sysname + */ + function factory($result, $sysname) + { + if (Net_Ping_Result::_prepareParseResult($sysname)) { + return PEAR::throwError(PING_RESULT_UNSUPPORTED_BACKEND_MSG, PING_RESULT_UNSUPPORTED_BACKEND); + } else { + return new Net_Ping_Result($result, $sysname); + } + } + + /** + * Preparation method for _parseResult + * + * @access private + * @param string $sysname OS_Guess::sysname + * $return bool + */ + function _prepareParseResult($sysname) + { + return method_exists('Net_Ping_Result', '_parseResult'.$sysname); + } + + /** + * Delegates the parsing routine according to $this->_sysname + * + * @access private + */ + function _parseResult() + { + call_user_func(array(&$this, '_parseResult'.$this->_sysname)); + } + + /** + * Parses the output of Linux' ping command + * + * @access private + * @see _parseResultlinux + */ + function _parseResultlinux() + { + $raw_data_len = count($this->_raw_data); + $icmp_seq_count = $raw_data_len - 4; + + /* loop from second elment to the fifths last */ + for($idx = 1; $idx < $icmp_seq_count; $idx++) + { + $parts = explode(' ', $this->_raw_data[$idx]); + $this->_icmp_sequence[substr($parts[4], 9, strlen($parts[4]))] = substr($parts[6], 5, strlen($parts[6])); + } + $this->_bytes_per_request = $parts[0]; + $this->_bytes_total = (int)$parts[0] * $icmp_seq_count; + $this->_target_ip = substr($parts[3], 0, -1); + $this->_ttl = substr($parts[5], 4, strlen($parts[3])); + + $stats = explode(',', $this->_raw_data[$raw_data_len - 2]); + $transmitted = explode(' ', $stats[0]); + $this->_transmitted = $transmitted[0]; + + $received = explode(' ', $stats[1]); + $this->_received = $received[1]; + + $loss = explode(' ', $stats[2]); + $this->_loss = (int)$loss[1]; + + $round_trip = explode('/', str_replace('=', '/', substr($this->_raw_data[$raw_data_len - 1], 0, -3))); + + $this->_round_trip['min'] = ltrim($round_trip[3]); + $this->_round_trip['avg'] = $round_trip[4]; + $this->_round_trip['max'] = $round_trip[5]; + } + + /** + * Parses the output of NetBSD's ping command + * + * @access private + * @see _parseResultfreebsd + */ + function _parseResultnetbsd() + { + $this->_parseResultfreebsd(); + } + + /** + * Parses the output of FreeBSD's ping command + * + * @access private + * @see _parseResultfreebsd + */ + function _parseResultfreebsd() + { + $raw_data_len = count($this->_raw_data); + $icmp_seq_count = $raw_data_len - 4; + + /* loop from second elment to the fifths last */ + for($idx = 1; $idx < $icmp_seq_count; $idx++) + { + $parts = explode(' ', $this->_raw_data[$idx]); + $this->_icmp_sequence[substr($parts[4], 9, strlen($parts[4]))] = substr($parts[6], 5, strlen($parts[6])); + } + $this->_bytes_per_request = $parts[0]; + $this->_bytes_total = (int)$parts[0] * $icmp_seq_count; + $this->_target_ip = substr($parts[3], 0, -1); + $this->_ttl = substr($parts[5], 4, strlen($parts[3])); + + $stats = explode(',', $this->_raw_data[$raw_data_len - 2]); + $transmitted = explode(' ', $stats[0]); + $this->_transmitted = $transmitted[0]; + + $received = explode(' ', $stats[1]); + $this->_received = $received[1]; + + $loss = explode(' ', $stats[2]); + $this->_loss = (int)$loss[1]; + + $round_trip = explode('/', str_replace('=', '/', substr($this->_raw_data[$raw_data_len - 1], 0, -3))); + + $this->_round_trip['min'] = ltrim($round_trip[4]); + $this->_round_trip['avg'] = $round_trip[5]; + $this->_round_trip['max'] = $round_trip[6]; + $this->_round_trip['stddev'] = $round_trip[7]; + + } + + /** + * Returns a Ping_Result property + * + * @param string $name property name + * @return mixed property value + * @access public + */ + function getValue($name) + { + return isset($this->$name)?$this->$name:''; + } + + /** + * Accessor for $this->_target_ip; + * + * @return string IP address + * @access public + * @see Ping_Result::_target_ip + */ + function getTargetIp() + { + return $this->_target_ip; + } + + /** + * Accessor for $this->_icmp_sequence; + * + * @return array ICMP sequence + * @access private + * @see Ping_Result::_icmp_sequence + */ + function getICMPSequence() + { + return $this->_icmp_sequence; + } + + /** + * Accessor for $this->_bytes_per_request; + * + * @return int bytes per request + * @access private + * @see Ping_Result::_bytes_per_request + */ + function getBytesPerRequest() + { + return $this->_bytes_per_request; + } + + /** + * Accessor for $this->_bytes_total; + * + * @return int total bytes + * @access private + * @see Ping_Result::_bytes_total + */ + function getBytesTotal() + { + return $this->_bytes_total; + } + + /** + * Accessor for $this->_ttl; + * + * @return int TTL + * @access private + * @see Ping_Result::_ttl + */ + function getTTL() + { + return $this->_ttl; + } + + /** + * Accessor for $this->_raw_data; + * + * @return array raw data + * @access private + * @see Ping_Result::_raw_data + */ + function getRawData() + { + return $this->_raw_data; + } + + /** + * Accessor for $this->_sysname; + * + * @return string OS_Guess::sysname + * @access private + * @see Ping_Result::_sysname + */ + function getSystemName() + { + return $this->_sysname; + } + + /** + * Accessor for $this->_round_trip; + * + * @return array statistical information + * @access private + * @see Ping_Result::_round_trip + */ + function getRoundTrip() + { + return $this->_round_trip; + } + } ?> Index: pear/Net_Ping/package.xml diff -u pear/Net_Ping/package.xml:1.10 pear/Net_Ping/package.xml:1.11 --- pear/Net_Ping/package.xml:1.10 Sun May 26 19:06:43 2002 +++ pear/Net_Ping/package.xml Wed Feb 5 06:34:31 2003 @@ -5,6 +5,8 @@ <package version="1.0"> <name>Net_Ping</name> <summary>Execute ping</summary> + <description>OS independet wrapper class for executing ping calls</description> + <license>PHP License</license> <maintainers> <maintainer> <user>mj</user> @@ -26,13 +28,12 @@ </maintainer> </maintainers> <release> - <version>2.0</version> - <date>2002-05-27</date> + <version>2.1</version> + <date>2003-02-05</date> <state>beta</state> <notes> - * Rewrite to handle platform differences - * Added the checkHost() method - * Added parameter to specify maximum wait time (-w) + * Added result object + * Introdiced PEAR error handling </notes> <filelist> <dir name="/" baseinstalldir="Net"> @@ -40,4 +41,21 @@ </dir> </filelist> </release> + <changelog> + <release> + <version>2.0</version> + <date>2002-05-27</date> + <state>beta</state> + <notes> + * Rewrite to handle platform differences + * Added the checkHost() method + * Added parameter to specify maximum wait time (-w) + </notes> + <filelist> + <dir name="/" baseinstalldir="Net"> + <file role="php" name="Ping.php" /> + </dir> + </filelist> + </release> + </changelog> </package>
Index: pear/Net_Ping/Ping.php diff -u pear/Net_Ping/Ping.php:1.20 pear/Net_Ping/Ping.php:1.21 --- pear/Net_Ping/Ping.php:1.20 Sat Jan 4 06:55:51 2003 +++ pear/Net_Ping/Ping.php Wed Feb 5 06:34:30 2003 @@ -19,18 +19,26 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Ping.php,v 1.20 2003/01/04 11:55:51 mj Exp $ +// $Id: Ping.php,v 1.21 2003/02/05 11:34:30 jan Exp $ require_once "PEAR.php"; require_once "OS/Guess.php"; -define('PING_FAILED', 'execution of ping failed'); -define('PING_HOST_NOT_FOUND', 'unknown host'); -define('PING_INVALID_ARGUMENTS', 'invalid argument array'); +define('PING_FAILED_MSG', 'execution of ping failed'); +define('PING_HOST_NOT_FOUND_MSG', 'unknown host'); +define('PING_INVALID_ARGUMENTS_MSG', 'invalid argument array'); +define('PING_CANT_LOCATE_PING_BINARY_MSG', 'unable to locate the ping binary'); +define('PING_RESULT_UNSUPPORTED_BACKEND_MSG', 'Backend not Supported'); + +define('PING_FAILED', 0); +define('PING_HOST_NOT_FOUND', 1); +define('PING_INVALID_ARGUMENTS', 2); +define('PING_CANT_LOCATE_PING_BINARY', 3); +define('PING_RESULT_UNSUPPORTED_BACKEND', 4); /**************************TODO*******************************************/ /* -return an object with ping results, make raw, ping data optional + */ /** @@ -40,23 +48,22 @@ * * <?php * require_once "Net_Ping/Ping.php"; -* $ping = new Net_Ping; -* $ping->setArgs(array("count" => 5), -* "size" => 32), -* "ttl" => 512) -* ) -* ); -* var_dump($ping->ping("example.com")); +* $ping = Net_Ping::factory(); +* if(PEAR::isError($ping)) { +* echo $ping->getMessage(); +* } else { +* $ping->setArgs(array('count' => 2)); +* var_dump($ping->ping('example.com')); +* } * ?> * -* @author Martin Jansen <mj@php.net> -* @version $Revision: 1.20 $ +* @author Jan Lehnardt <jan@php.net> +* @version $Revision: 1.21 $ * @package Net * @access public */ class Net_Ping { - /** * Location where the ping program is stored * @@ -113,22 +120,37 @@ */ var $_argRelation = array(); - /** * Constructor for the Class * * @access private */ - function Net_Ping() + function Net_Ping($ping_path, $sysname) { - $this->_OS_Guess = new OS_Guess; - $this->_sysname = $this->_OS_Guess->getSysname(); - - $this->_setPingPath(); + $this->_ping_path = $ping_path; + $this->_sysname = $sysname; $this->_initArgRelation(); } /** + * Factory for Net_Ping + * + * @access public + */ + function factory() + { + $OS_Guess = new OS_Guess; + $sysname = $OS_Guess->getSysname(); + $ping_path = ''; + + if (($ping_path = Net_Ping::_setPingPath($sysname)) == PING_CANT_LOCATE_PING_BINARY) { + return PEAR::throwError(PING_CANT_LOCATE_PING_BINARY_MSG, PING_CANT_LOCATE_PING_BINARY); + } else { + return new Net_Ping($ping_path, $sysname); + } + + } + /** * Set the arguments array * * @param array $args Hash with options @@ -138,7 +160,7 @@ function setArgs($args) { if (!is_array($args)) { - return PEAR::raiseError(PING_INVALID_ARGUMENTS); + return PEAR::throwError(PING_INVALID_ARGUMENTS_MSG, PING_INVALID_ARGUMENTS); } /* accept empty arrays, but set flag*/ @@ -158,12 +180,21 @@ * * @access private */ - function _setPingPath() + function _setPingPath($sysname) { - if ("windows" == $this->_sysname) { - $this->_ping_path = "ping"; + $status = ''; + $output = array(); + $ping_path = ''; + + if ("windows" == $sysname) { + return "ping"; } else { - $this->_ping_path = exec("which ping"); /* FIXME: windows */ + $ping_path = exec("which ping", $output, $status); + if (0 != $status) { + return PING_CANT_LOCATE_PING_BINARY; + } else { + return $ping_path; + } } } @@ -254,13 +285,13 @@ exec($cmd, $this->_result); if (!is_array($this->_result)) { - return PING_FAILED; + return PEAR::throwError(PING_FAILED_MSG, PING_FAILED); } if (count($this->_result) == 0) { - return PING_HOST_NOT_FOUND; + return PEAR::throwError(PING_HOST_NOT_FOUND_MSG, PING_HOST_NOT_FOUND); } else { - return $this->_result; + return Net_Ping_Result::factory($this->_result, $this->_sysname); } } @@ -282,7 +313,7 @@ ) ); $res = $this->ping($host); - if ($res == PING_HOST_NOT_FOUND) { + if (PEAR::isError($res)) { return false; } if (!preg_match_all('|\d+|', $res[3], $m) || count($m[0]) < 3) { @@ -381,5 +412,333 @@ } +} + + +/** +* Container class for Net_Ping results +* +* @author Jan Lehnardt <jan@php.net> +* @version $Revision: 1.21 $ +* @package Net +* @access private +*/ +class Net_Ping_Result +{ + /** + * ICMP sequence number and associated time in ms + * + * @var array + * @access private + */ + var $_icmp_sequence = array(); /* array($sequence_number => $time ) */ + + /** + * The target's IP Address + * + * @var string + * @access private + */ + var $_target_ip; + + /** + * Number of bytes that are sent with each ICMP request + * + * @var int + * @access private + */ + var $_bytes_per_request; + + /** + * The total number of bytes that are sent with all ICMP requests + * + * @var int + * @access private + */ + var $_bytes_total; + + /** + * The ICMP request's TTL + * + * @var int + * @access private + */ + var $_ttl; + + /** + * The raw Net_Ping::result + * + * @var array + * @access private + */ + var $_raw_data = array(); + + /** + * The Net_Ping::_sysname + * + * @var int + * @access private + */ + var $_sysname; + + /** + * Statistical information about the ping + * + * @var int + * @access private + */ + var $_round_trip = array(); /* array('min' => xxx, 'avg' => yyy, 'max' => zzz) */ + + + /** + * Constructor for the Class + * + * @access private + */ + function Net_Ping_Result($result, $sysname) + { + $this->_raw_data = $result; + $this->_sysname = $sysname; + + $this->_parseResult(); + } + + /** + * Factory for Net_Ping_Result + * + * @access public + * @param array $result Net_Ping result + * @param string $sysname OS_Guess::sysname + */ + function factory($result, $sysname) + { + if (Net_Ping_Result::_prepareParseResult($sysname)) { + return PEAR::throwError(PING_RESULT_UNSUPPORTED_BACKEND_MSG, PING_RESULT_UNSUPPORTED_BACKEND); + } else { + return new Net_Ping_Result($result, $sysname); + } + } + + /** + * Preparation method for _parseResult + * + * @access private + * @param string $sysname OS_Guess::sysname + * $return bool + */ + function _prepareParseResult($sysname) + { + return method_exists('Net_Ping_Result', '_parseResult'.$sysname); + } + + /** + * Delegates the parsing routine according to $this->_sysname + * + * @access private + */ + function _parseResult() + { + call_user_func(array(&$this, '_parseResult'.$this->_sysname)); + } + + /** + * Parses the output of Linux' ping command + * + * @access private + * @see _parseResultlinux + */ + function _parseResultlinux() + { + $raw_data_len = count($this->_raw_data); + $icmp_seq_count = $raw_data_len - 4; + + /* loop from second elment to the fifths last */ + for($idx = 1; $idx < $icmp_seq_count; $idx++) + { + $parts = explode(' ', $this->_raw_data[$idx]); + $this->_icmp_sequence[substr($parts[4], 9, strlen($parts[4]))] = substr($parts[6], 5, strlen($parts[6])); + } + $this->_bytes_per_request = $parts[0]; + $this->_bytes_total = (int)$parts[0] * $icmp_seq_count; + $this->_target_ip = substr($parts[3], 0, -1); + $this->_ttl = substr($parts[5], 4, strlen($parts[3])); + + $stats = explode(',', $this->_raw_data[$raw_data_len - 2]); + $transmitted = explode(' ', $stats[0]); + $this->_transmitted = $transmitted[0]; + + $received = explode(' ', $stats[1]); + $this->_received = $received[1]; + + $loss = explode(' ', $stats[2]); + $this->_loss = (int)$loss[1]; + + $round_trip = explode('/', str_replace('=', '/', substr($this->_raw_data[$raw_data_len - 1], 0, -3))); + + $this->_round_trip['min'] = ltrim($round_trip[3]); + $this->_round_trip['avg'] = $round_trip[4]; + $this->_round_trip['max'] = $round_trip[5]; + } + + /** + * Parses the output of NetBSD's ping command + * + * @access private + * @see _parseResultfreebsd + */ + function _parseResultnetbsd() + { + $this->_parseResultfreebsd(); + } + + /** + * Parses the output of FreeBSD's ping command + * + * @access private + * @see _parseResultfreebsd + */ + function _parseResultfreebsd() + { + $raw_data_len = count($this->_raw_data); + $icmp_seq_count = $raw_data_len - 4; + + /* loop from second elment to the fifths last */ + for($idx = 1; $idx < $icmp_seq_count; $idx++) + { + $parts = explode(' ', $this->_raw_data[$idx]); + $this->_icmp_sequence[substr($parts[4], 9, strlen($parts[4]))] = substr($parts[6], 5, strlen($parts[6])); + } + $this->_bytes_per_request = $parts[0]; + $this->_bytes_total = (int)$parts[0] * $icmp_seq_count; + $this->_target_ip = substr($parts[3], 0, -1); + $this->_ttl = substr($parts[5], 4, strlen($parts[3])); + + $stats = explode(',', $this->_raw_data[$raw_data_len - 2]); + $transmitted = explode(' ', $stats[0]); + $this->_transmitted = $transmitted[0]; + + $received = explode(' ', $stats[1]); + $this->_received = $received[1]; + + $loss = explode(' ', $stats[2]); + $this->_loss = (int)$loss[1]; + + $round_trip = explode('/', str_replace('=', '/', substr($this->_raw_data[$raw_data_len - 1], 0, -3))); + + $this->_round_trip['min'] = ltrim($round_trip[4]); + $this->_round_trip['avg'] = $round_trip[5]; + $this->_round_trip['max'] = $round_trip[6]; + $this->_round_trip['stddev'] = $round_trip[7]; + + } + + /** + * Returns a Ping_Result property + * + * @param string $name property name + * @return mixed property value + * @access public + */ + function getValue($name) + { + return isset($this->$name)?$this->$name:''; + } + + /** + * Accessor for $this->_target_ip; + * + * @return string IP address + * @access public + * @see Ping_Result::_target_ip + */ + function getTargetIp() + { + return $this->_target_ip; + } + + /** + * Accessor for $this->_icmp_sequence; + * + * @return array ICMP sequence + * @access private + * @see Ping_Result::_icmp_sequence + */ + function getICMPSequence() + { + return $this->_icmp_sequence; + } + + /** + * Accessor for $this->_bytes_per_request; + * + * @return int bytes per request + * @access private + * @see Ping_Result::_bytes_per_request + */ + function getBytesPerRequest() + { + return $this->_bytes_per_request; + } + + /** + * Accessor for $this->_bytes_total; + * + * @return int total bytes + * @access private + * @see Ping_Result::_bytes_total + */ + function getBytesTotal() + { + return $this->_bytes_total; + } + + /** + * Accessor for $this->_ttl; + * + * @return int TTL + * @access private + * @see Ping_Result::_ttl + */ + function getTTL() + { + return $this->_ttl; + } + + /** + * Accessor for $this->_raw_data; + * + * @return array raw data + * @access private + * @see Ping_Result::_raw_data + */ + function getRawData() + { + return $this->_raw_data; + } + + /** + * Accessor for $this->_sysname; + * + * @return string OS_Guess::sysname + * @access private + * @see Ping_Result::_sysname + */ + function getSystemName() + { + return $this->_sysname; + } + + /** + * Accessor for $this->_round_trip; + * + * @return array statistical information + * @access private + * @see Ping_Result::_round_trip + */ + function getRoundTrip() + { + return $this->_round_trip; + } + } ?> Index: pear/Net_Ping/package.xml diff -u pear/Net_Ping/package.xml:1.10 pear/Net_Ping/package.xml:1.11 --- pear/Net_Ping/package.xml:1.10 Sun May 26 19:06:43 2002 +++ pear/Net_Ping/package.xml Wed Feb 5 06:34:31 2003 @@ -5,6 +5,8 @@ <package version="1.0"> <name>Net_Ping</name> <summary>Execute ping</summary> + <description>OS independet wrapper class for executing ping calls</description> + <license>PHP License</license> <maintainers> <maintainer> <user>mj</user> @@ -26,13 +28,12 @@ </maintainer> </maintainers> <release> - <version>2.0</version> - <date>2002-05-27</date> + <version>2.1</version> + <date>2003-02-05</date> <state>beta</state> <notes> - * Rewrite to handle platform differences - * Added the checkHost() method - * Added parameter to specify maximum wait time (-w) + * Added result object + * Introdiced PEAR error handling </notes> <filelist> <dir name="/" baseinstalldir="Net"> @@ -40,4 +41,21 @@ </dir> </filelist> </release> + <changelog> + <release> + <version>2.0</version> + <date>2002-05-27</date> + <state>beta</state> + <notes> + * Rewrite to handle platform differences + * Added the checkHost() method + * Added parameter to specify maximum wait time (-w) + </notes> + <filelist> + <dir name="/" baseinstalldir="Net"> + <file role="php" name="Ping.php" /> + </dir> + </filelist> + </release> + </changelog> </package>