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
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
32 #include <ipxe/command.h>
33 #include <ipxe/parseopt.h>
34 #include <ipxe/timer.h>
35 #include <usr/pingmgmt.h>
43 /** Default payload length */
44 #define PING_DEFAULT_SIZE 64
46 /** Default timeout */
47 #define PING_DEFAULT_TIMEOUT TICKS_PER_SEC
53 /** Timeout (in ms) */
54 unsigned long timeout;
55 /** Number of packets to send (or zero for no limit) */
61 /** "ping" option list */
62 static struct option_descriptor ping_opts[] = {
63 OPTION_DESC ( "size", 's', required_argument,
64 struct ping_options, size, parse_integer ),
65 OPTION_DESC ( "timeout", 't', required_argument,
66 struct ping_options, timeout, parse_timeout ),
67 OPTION_DESC ( "count", 'c', required_argument,
68 struct ping_options, count, parse_integer ),
69 OPTION_DESC ( "quiet", 'q', no_argument,
70 struct ping_options, quiet, parse_flag ),
73 /** "ping" command descriptor */
74 static struct command_descriptor ping_cmd =
75 COMMAND_DESC ( struct ping_options, ping_opts, 1, 1, "<host>" );
80 * @v argc Argument count
81 * @v argv Argument list
82 * @ret rc Return status code
84 static int ping_exec ( int argc, char **argv ) {
85 struct ping_options opts;
89 /* Initialise options */
90 memset ( &opts, 0, sizeof ( opts ) );
91 opts.size = PING_DEFAULT_SIZE;
92 opts.timeout = PING_DEFAULT_TIMEOUT;
95 if ( ( rc = reparse_options ( argc, argv, &ping_cmd, &opts ) ) != 0 )
99 hostname = argv[optind];
102 if ( ( rc = ping ( hostname, opts.timeout, opts.size,
103 opts.count, opts.quiet ) ) != 0 )
110 struct command ping_command __command = {