int rc;
/* If no response has been received, notify the callback function */
- if ( pinger->pending )
+ if ( pinger->pending && pinger->callback )
pinger->callback ( NULL, pinger->sequence, 0, -ETIMEDOUT );
/* Check for termination */
/* Discard I/O buffer */
free_iob ( iobuf );
- /* Notify callback function */
- pinger->callback ( meta->src, sequence, len, rc );
+ /* Notify callback function, if applicable */
+ if ( pinger->callback )
+ pinger->callback ( meta->src, sequence, len, rc );
/* Terminate if applicable */
if ( terminate )
* @v timeout Timeout (in ticks)
* @v len Payload length
* @v count Number of packets to send (or zero for no limit)
+ * @v callback Callback function (or NULL)
* @ret rc Return status code
*/
int create_pinger ( struct interface *job, const char *hostname,
unsigned long timeout;
/** Number of packets to send (or zero for no limit) */
unsigned int count;
+ /** Inhibit output */
+ int quiet;
};
/** "ping" option list */
struct ping_options, timeout, parse_timeout ),
OPTION_DESC ( "count", 'c', required_argument,
struct ping_options, count, parse_integer ),
+ OPTION_DESC ( "quiet", 'q', no_argument,
+ struct ping_options, quiet, parse_flag ),
};
/** "ping" command descriptor */
/* Ping */
if ( ( rc = ping ( hostname, opts.timeout, opts.size,
- opts.count ) ) != 0 )
+ opts.count, opts.quiet ) ) != 0 )
return rc;
return 0;
#include <stdint.h>
extern int ping ( const char *hostname, unsigned long timeout, size_t len,
- unsigned int count );
+ unsigned int count, int quiet );
#endif /* _USR_PINGMGMT_H */
* @v timeout Timeout between pings, in ticks
* @v len Payload length
* @v count Number of packets to send (or zero for no limit)
+ * @v quiet Inhibit output
* @ret rc Return status code
*/
int ping ( const char *hostname, unsigned long timeout, size_t len,
- unsigned int count ) {
+ unsigned int count, int quiet ) {
int rc;
/* Create pinger */
- if ( ( rc = create_pinger ( &monojob, hostname, timeout, len,
- count, ping_callback ) ) != 0 ) {
+ if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, count,
+ ( quiet ? NULL : ping_callback ) ) ) != 0 ){
printf ( "Could not start ping: %s\n", strerror ( rc ) );
return rc;
}
/* Wait for ping to complete */
if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
- printf ( "Finished: %s\n", strerror ( rc ) );
+ if ( ! quiet )
+ printf ( "Finished: %s\n", strerror ( rc ) );
return rc;
}