iPXE
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...

Macros

#define PING_DEFAULT_SIZE   64
 Default payload length.
#define PING_DEFAULT_TIMEOUT   TICKS_PER_SEC
 Default timeout.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int ping_exec (int argc, char **argv)
 The "ping" command.
 COMMAND (ping, ping_exec)
 Ping command.

Variables

static struct option_descriptor ping_opts []
 "ping" option list
static struct command_descriptor ping_cmd
 "ping" command descriptor

Detailed Description

Ping command.

Definition in file ping_cmd.c.

Macro Definition Documentation

◆ PING_DEFAULT_SIZE

#define PING_DEFAULT_SIZE   64

Default payload length.

Definition at line 45 of file ping_cmd.c.

Referenced by ping_exec().

◆ PING_DEFAULT_TIMEOUT

#define PING_DEFAULT_TIMEOUT   TICKS_PER_SEC

Default timeout.

Definition at line 48 of file ping_cmd.c.

Referenced by ping_exec().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ping_exec()

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

The "ping" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 85 of file ping_cmd.c.

85 {
86 struct ping_options opts;
87 const char *hostname;
88 int rc;
89
90 /* Initialise options */
91 memset ( &opts, 0, sizeof ( opts ) );
93 opts.timeout = PING_DEFAULT_TIMEOUT;
94
95 /* Parse options */
96 if ( ( rc = reparse_options ( argc, argv, &ping_cmd, &opts ) ) != 0 )
97 return rc;
98
99 /* Parse hostname */
100 hostname = argv[optind];
101
102 /* Ping */
103 if ( ( rc = ping ( hostname, opts.timeout, opts.size,
104 opts.count, opts.quiet ) ) != 0 )
105 return rc;
106
107 return 0;
108}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
int optind
Current option index.
Definition getopt.c:52
void * memset(void *dest, int character, size_t len) __nonnull
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition parseopt.c:402
#define PING_DEFAULT_SIZE
Default payload length.
Definition ping_cmd.c:45
static struct command_descriptor ping_cmd
"ping" command descriptor
Definition ping_cmd.c:75
#define PING_DEFAULT_TIMEOUT
Default timeout.
Definition ping_cmd.c:48
int ping(const char *hostname, unsigned long timeout, size_t len, unsigned int count, int quiet)
Ping a host.
Definition pingmgmt.c:70
"ping" options
Definition ping_cmd.c:51

References memset(), optind, opts, ping(), ping_cmd, PING_DEFAULT_SIZE, PING_DEFAULT_TIMEOUT, rc, and reparse_options().

Referenced by COMMAND().

◆ COMMAND()

COMMAND ( ping ,
ping_exec  )

Ping command.

References ping(), and ping_exec().

Variable Documentation

◆ ping_opts

struct option_descriptor ping_opts[]
static
Initial value:
= {
OPTION_DESC ( "timeout", 't', required_argument,
OPTION_DESC ( "count", 'c', required_argument,
OPTION_DESC ( "quiet", 'q', no_argument,
struct ping_options, quiet, parse_flag ),
}
void timeout(int)
@ required_argument
Option requires an argument.
Definition getopt.h:19
@ no_argument
Option does not take an argument.
Definition getopt.h:17
uint16_t size
Buffer size.
Definition dwmac.h:3
static unsigned int count
Number of entries.
Definition dwmac.h:220
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition parseopt.c:227
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition parseopt.c:92
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition parseopt.c:115
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68

"ping" option list

Definition at line 63 of file ping_cmd.c.

63 {
64 OPTION_DESC ( "size", 's', required_argument,
66 OPTION_DESC ( "timeout", 't', required_argument,
68 OPTION_DESC ( "count", 'c', required_argument,
70 OPTION_DESC ( "quiet", 'q', no_argument,
71 struct ping_options, quiet, parse_flag ),
72};

◆ ping_cmd

struct command_descriptor ping_cmd
static
Initial value:
=
COMMAND_DESC ( struct ping_options, ping_opts, 1, 1, "<host>" )
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109
static struct option_descriptor ping_opts[]
"ping" option list
Definition ping_cmd.c:63

"ping" command descriptor

Definition at line 75 of file ping_cmd.c.

Referenced by ping_exec(), and PROVIDE_REQUIRING_SYMBOL().