2 * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
28 #include <ipxe/command.h>
29 #include <ipxe/parseopt.h>
30 #include <ipxe/timer.h>
31 #include <usr/pingmgmt.h>
39 /** Default payload length */
40 #define PING_DEFAULT_SIZE 64
42 /** Default timeout */
43 #define PING_DEFAULT_TIMEOUT TICKS_PER_SEC
49 /** Timeout (in ms) */
50 unsigned long timeout;
51 /** Number of packets to send (or zero for no limit) */
57 /** "ping" option list */
58 static struct option_descriptor ping_opts[] = {
59 OPTION_DESC ( "size", 's', required_argument,
60 struct ping_options, size, parse_integer ),
61 OPTION_DESC ( "timeout", 't', required_argument,
62 struct ping_options, timeout, parse_timeout ),
63 OPTION_DESC ( "count", 'c', required_argument,
64 struct ping_options, count, parse_integer ),
65 OPTION_DESC ( "quiet", 'q', no_argument,
66 struct ping_options, quiet, parse_flag ),
69 /** "ping" command descriptor */
70 static struct command_descriptor ping_cmd =
71 COMMAND_DESC ( struct ping_options, ping_opts, 1, 1, "<host>" );
76 * @v argc Argument count
77 * @v argv Argument list
78 * @ret rc Return status code
80 static int ping_exec ( int argc, char **argv ) {
81 struct ping_options opts;
85 /* Initialise options */
86 memset ( &opts, 0, sizeof ( opts ) );
87 opts.size = PING_DEFAULT_SIZE;
88 opts.timeout = PING_DEFAULT_TIMEOUT;
91 if ( ( rc = reparse_options ( argc, argv, &ping_cmd, &opts ) ) != 0 )
95 hostname = argv[optind];
98 if ( ( rc = ping ( hostname, opts.timeout, opts.size,
99 opts.count, opts.quiet ) ) != 0 )
106 struct command ping_command __command = {