From 1c34ca70d199ceee9d663986e377b7f74c826d0c Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 23 Oct 2014 16:30:58 +0100 Subject: [ping] Allow termination after a specified number of packets Add the "-c " option to the "ping" command, allowing for automatic termination after a specified number of packets. When a number of packets is specified: - if a serious error (i.e. length mismatch or content mismatch) occurs, then the ping will be immediately terminated with the relevant status code; - if at least one response is received successfully, and all errors are non-serious (i.e. timeouts or out-of-sequence responses), then the ping will be terminated after the final response (or timeout) with a success status; - if no responses are received successfully, then the ping will be terminated after the final timeout with ETIMEDOUT. If no number of packets is specified, then the ping will continue until manually interrupted. Originally-implemented-by: Cedric Levasseur Signed-off-by: Michael Brown --- src/usr/pingmgmt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/usr') diff --git a/src/usr/pingmgmt.c b/src/usr/pingmgmt.c index cf6a5111..f8366f26 100644 --- a/src/usr/pingmgmt.c +++ b/src/usr/pingmgmt.c @@ -58,14 +58,16 @@ static void ping_callback ( struct sockaddr *peer, unsigned int sequence, * @v hostname Hostname * @v timeout Timeout between pings, in ticks * @v len Payload length + * @v count Number of packets to send (or zero for no limit) * @ret rc Return status code */ -int ping ( const char *hostname, unsigned long timeout, size_t len ) { +int ping ( const char *hostname, unsigned long timeout, size_t len, + unsigned int count ) { int rc; /* Create pinger */ - if ( ( rc = create_pinger ( &monojob, hostname, timeout, - len, ping_callback ) ) != 0 ) { + if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, + count, ping_callback ) ) != 0 ) { printf ( "Could not start ping: %s\n", strerror ( rc ) ); return rc; } -- cgit v1.2.3-55-g7522