瀏覽代碼

[cmdline] Add "ping" command

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 年之前
父節點
當前提交
6f43ba411d
共有 3 個文件被更改,包括 104 次插入0 次删除
  1. 3
    0
      src/config/config.c
  2. 1
    0
      src/config/general.h
  3. 100
    0
      src/hci/commands/ping_cmd.c

+ 3
- 0
src/config/config.c 查看文件

@@ -272,6 +272,9 @@ REQUIRE_OBJECT ( param_cmd );
272 272
 #ifdef NEIGHBOUR_CMD
273 273
 REQUIRE_OBJECT ( neighbour_cmd );
274 274
 #endif
275
+#ifdef PING_CMD
276
+REQUIRE_OBJECT ( ping_cmd );
277
+#endif
275 278
 
276 279
 /*
277 280
  * Drag in miscellaneous objects

+ 1
- 0
src/config/general.h 查看文件

@@ -133,6 +133,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
133 133
 //#define PCI_CMD		/* PCI commands */
134 134
 //#define PARAM_CMD		/* Form parameter commands */
135 135
 //#define NEIGHBOUR_CMD		/* Neighbour management commands */
136
+//#define PING_CMD		/* Ping command */
136 137
 
137 138
 /*
138 139
  * ROM-specific options

+ 100
- 0
src/hci/commands/ping_cmd.c 查看文件

@@ -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
+};

Loading…
取消
儲存