iPXE
Data Structures | Macros | 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...
 

Macros

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

Functions

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

Variables

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

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 44 of file ping_cmd.c.

◆ PING_DEFAULT_TIMEOUT

#define PING_DEFAULT_TIMEOUT   TICKS_PER_SEC

Default timeout.

Definition at line 47 of file ping_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ping_exec()

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

The "ping" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 84 of file ping_cmd.c.

84  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int optind
Current option index.
Definition: getopt.c:51
#define PING_DEFAULT_SIZE
Default payload length.
Definition: ping_cmd.c:44
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition: parseopt.c:401
static union @437 opts
"cert<xxx>" option list
#define PING_DEFAULT_TIMEOUT
Default timeout.
Definition: ping_cmd.c:47
static struct command_descriptor ping_cmd
"ping" command descriptor
Definition: ping_cmd.c:74
"ping" options
Definition: ping_cmd.c:50
int ping(const char *hostname, unsigned long timeout, size_t len, unsigned int count, int quiet)
Ping a host.
Definition: pingmgmt.c:69
void * memset(void *dest, int character, size_t len) __nonnull

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

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,
}
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:114
int quiet
Inhibit output.
Definition: ping_cmd.c:58
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition: parseopt.c:226
Option does not take an argument.
Definition: getopt.h:16
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
"ping" options
Definition: ping_cmd.c:50
Option requires an argument.
Definition: getopt.h:18
uint16_t count
Number of entries.
Definition: ena.h:22
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
void timeout(int)

"ping" option list

Definition at line 62 of file ping_cmd.c.

◆ ping_cmd

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

"ping" command descriptor

Definition at line 74 of file ping_cmd.c.

Referenced by ping_exec().

◆ __command

struct command ping_command __command
Initial value:
= {
.name = "ping",
.exec = ping_exec,
}
static int ping_exec(int argc, char **argv)
The "ping" command.
Definition: ping_cmd.c:84

Ping command.

Definition at line 110 of file ping_cmd.c.