~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/ipxe/src/hci/commands/ping_cmd.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * 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.
 
22
 */
 
23
 
 
24
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
25
 
 
26
#include <stdint.h>
 
27
#include <stdlib.h>
 
28
#include <stdio.h>
 
29
#include <string.h>
 
30
#include <errno.h>
 
31
#include <getopt.h>
 
32
#include <ipxe/command.h>
 
33
#include <ipxe/parseopt.h>
 
34
#include <ipxe/timer.h>
 
35
#include <usr/pingmgmt.h>
 
36
 
 
37
/** @file
 
38
 *
 
39
 * Ping command
 
40
 *
 
41
 */
 
42
 
 
43
/** Default payload length */
 
44
#define PING_DEFAULT_SIZE 64
 
45
 
 
46
/** Default timeout */
 
47
#define PING_DEFAULT_TIMEOUT TICKS_PER_SEC
 
48
 
 
49
/** "ping" options */
 
50
struct ping_options {
 
51
        /** Payload length */
 
52
        unsigned int size;
 
53
        /** Timeout (in ms) */
 
54
        unsigned long timeout;
 
55
        /** Number of packets to send (or zero for no limit) */
 
56
        unsigned int count;
 
57
        /** Inhibit output */
 
58
        int quiet;
 
59
};
 
60
 
 
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 ),
 
71
};
 
72
 
 
73
/** "ping" command descriptor */
 
74
static struct command_descriptor ping_cmd =
 
75
        COMMAND_DESC ( struct ping_options, ping_opts, 1, 1, "<host>" );
 
76
 
 
77
/**
 
78
 * The "ping" command
 
79
 *
 
80
 * @v argc              Argument count
 
81
 * @v argv              Argument list
 
82
 * @ret rc              Return status code
 
83
 */
 
84
static int ping_exec ( int argc, char **argv ) {
 
85
        struct ping_options opts;
 
86
        const char *hostname;
 
87
        int rc;
 
88
 
 
89
        /* Initialise options */
 
90
        memset ( &opts, 0, sizeof ( opts ) );
 
91
        opts.size = PING_DEFAULT_SIZE;
 
92
        opts.timeout = PING_DEFAULT_TIMEOUT;
 
93
 
 
94
        /* Parse options */
 
95
        if ( ( rc = reparse_options ( argc, argv, &ping_cmd, &opts ) ) != 0 )
 
96
                return rc;
 
97
 
 
98
        /* Parse hostname */
 
99
        hostname = argv[optind];
 
100
 
 
101
        /* Ping */
 
102
        if ( ( rc = ping ( hostname, opts.timeout, opts.size,
 
103
                           opts.count, opts.quiet ) ) != 0 )
 
104
                return rc;
 
105
 
 
106
        return 0;
 
107
}
 
108
 
 
109
/** Ping command */
 
110
struct command ping_command __command = {
 
111
        .name = "ping",
 
112
        .exec = ping_exec,
 
113
};