|
@@ -0,0 +1,100 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
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.
|
|
8
|
+ *
|
|
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.
|
|
13
|
+ *
|
|
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
|
|
17
|
+ * 02110-1301, USA.
|
|
18
|
+ */
|
|
19
|
+
|
|
20
|
+FILE_LICENCE ( GPL2_OR_LATER );
|
|
21
|
+
|
|
22
|
+#include <stdint.h>
|
|
23
|
+#include <stdlib.h>
|
|
24
|
+#include <stdio.h>
|
|
25
|
+#include <string.h>
|
|
26
|
+#include <errno.h>
|
|
27
|
+#include <getopt.h>
|
|
28
|
+#include <ipxe/command.h>
|
|
29
|
+#include <ipxe/parseopt.h>
|
|
30
|
+#include <usr/pingmgmt.h>
|
|
31
|
+
|
|
32
|
+/** @file
|
|
33
|
+ *
|
|
34
|
+ * Ping command
|
|
35
|
+ *
|
|
36
|
+ */
|
|
37
|
+
|
|
38
|
+/** Default payload length */
|
|
39
|
+#define PING_DEFAULT_SIZE 64
|
|
40
|
+
|
|
41
|
+/** Default timeout */
|
|
42
|
+#define PING_DEFAULT_TIMEOUT 1000
|
|
43
|
+
|
|
44
|
+/** "ping" options */
|
|
45
|
+struct ping_options {
|
|
46
|
+ /** Payload length */
|
|
47
|
+ unsigned int size;
|
|
48
|
+ /** Timeout (in ms) */
|
|
49
|
+ unsigned int timeout;
|
|
50
|
+};
|
|
51
|
+
|
|
52
|
+/** "ping" option list */
|
|
53
|
+static struct option_descriptor ping_opts[] = {
|
|
54
|
+ OPTION_DESC ( "size", 's', required_argument,
|
|
55
|
+ struct ping_options, size, parse_integer ),
|
|
56
|
+ OPTION_DESC ( "timeout", 't', required_argument,
|
|
57
|
+ struct ping_options, timeout, parse_integer ),
|
|
58
|
+};
|
|
59
|
+
|
|
60
|
+/** "ping" command descriptor */
|
|
61
|
+static struct command_descriptor ping_cmd =
|
|
62
|
+ COMMAND_DESC ( struct ping_options, ping_opts, 1, 1,
|
|
63
|
+ "[--size <size>] [--timeout <timeout>] <host>" );
|
|
64
|
+
|
|
65
|
+/**
|
|
66
|
+ * The "ping" command
|
|
67
|
+ *
|
|
68
|
+ * @v argc Argument count
|
|
69
|
+ * @v argv Argument list
|
|
70
|
+ * @ret rc Return status code
|
|
71
|
+ */
|
|
72
|
+static int ping_exec ( int argc, char **argv ) {
|
|
73
|
+ struct ping_options opts;
|
|
74
|
+ const char *hostname;
|
|
75
|
+ int rc;
|
|
76
|
+
|
|
77
|
+ /* Initialise options */
|
|
78
|
+ memset ( &opts, 0, sizeof ( opts ) );
|
|
79
|
+ opts.size = PING_DEFAULT_SIZE;
|
|
80
|
+ opts.timeout = PING_DEFAULT_TIMEOUT;
|
|
81
|
+
|
|
82
|
+ /* Parse options */
|
|
83
|
+ if ( ( rc = reparse_options ( argc, argv, &ping_cmd, &opts ) ) != 0 )
|
|
84
|
+ return rc;
|
|
85
|
+
|
|
86
|
+ /* Parse hostname */
|
|
87
|
+ hostname = argv[optind];
|
|
88
|
+
|
|
89
|
+ /* Ping */
|
|
90
|
+ if ( ( rc = ping ( hostname, opts.timeout, opts.size ) ) != 0 )
|
|
91
|
+ return rc;
|
|
92
|
+
|
|
93
|
+ return 0;
|
|
94
|
+}
|
|
95
|
+
|
|
96
|
+/** Ping command */
|
|
97
|
+struct command ping_command __command = {
|
|
98
|
+ .name = "ping",
|
|
99
|
+ .exec = ping_exec,
|
|
100
|
+};
|