Data Structures | Defines | Functions | Variables
ping_cmd.c File Reference

Ping command. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/timer.h>
#include <usr/pingmgmt.h>

Go to the source code of this file.

Data Structures

struct  ping_options
 "ping" options More...


#define PING_DEFAULT_SIZE   64
 Default payload length.
 Default timeout.


static int ping_exec (int argc, char **argv)
 The "ping" command.


static struct option_descriptor ping_opts []
 "ping" option list
static struct command_descriptor ping_cmd
 "ping" command descriptor
struct command ping_command __command
 Ping command.

Detailed Description

Ping command.

Definition in file ping_cmd.c.

Define Documentation

#define PING_DEFAULT_SIZE   64

Default payload length.

Definition at line 44 of file ping_cmd.c.

Referenced by ping_exec().

Default timeout.

Definition at line 47 of file ping_cmd.c.

Referenced by ping_exec().

Function Documentation

static int ping_exec ( int  argc,
char **  argv 
) [static]

The "ping" command.

argcArgument count
argvArgument list
Return values:
rcReturn status code

Definition at line 84 of file ping_cmd.c.

References ping_options::count, memset(), optind, ping(), PING_DEFAULT_SIZE, PING_DEFAULT_TIMEOUT, ping_options::quiet, rc, reparse_options(), ping_options::size, and ping_options::timeout.

        struct ping_options opts;
        const char *hostname;
        int rc;

        /* Initialise options */
        memset ( &opts, 0, sizeof ( opts ) );
        opts.size = PING_DEFAULT_SIZE;
        opts.timeout = PING_DEFAULT_TIMEOUT;

        /* Parse options */
        if ( ( rc = reparse_options ( argc, argv, &ping_cmd, &opts ) ) != 0 )
                return rc;

        /* Parse hostname */
        hostname = argv[optind];

        /* Ping */
        if ( ( rc = ping ( hostname, opts.timeout, opts.size,
                           opts.count, opts.quiet ) ) != 0 )
                return rc;

        return 0;

Variable Documentation

struct option_descriptor ping_opts[] [static]
Initial value:

"ping" option list

Definition at line 62 of file ping_cmd.c.

struct command_descriptor ping_cmd [static]
Initial value:
        COMMAND_DESC ( struct ping_options, ping_opts, 1, 1, "<host>" )

"ping" command descriptor

Definition at line 74 of file ping_cmd.c.

struct command ping_command __command
Initial value:
        .name = "ping",
        .exec = ping_exec,

Ping command.

Definition at line 110 of file ping_cmd.c.