iPXE
Functions
pingmgmt.c File Reference

ICMP ping management. More...

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <ipxe/pinger.h>
#include <ipxe/monojob.h>
#include <ipxe/timer.h>
#include <usr/pingmgmt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void ping_callback (struct sockaddr *peer, unsigned int sequence, size_t len, int rc)
 Display ping result. More...
 
int ping (const char *hostname, unsigned long timeout, size_t len, unsigned int count, int quiet)
 Ping a host. More...
 

Detailed Description

ICMP ping management.

Definition in file pingmgmt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ping_callback()

static void ping_callback ( struct sockaddr peer,
unsigned int  sequence,
size_t  len,
int  rc 
)
static

Display ping result.

Parameters
srcSource socket address, or NULL
sequenceSequence number
lenPayload length
rcStatus code

Definition at line 48 of file pingmgmt.c.

49  {
50 
51  /* Display ping response */
52  printf ( "%zd bytes from %s: seq=%d",
53  len, ( peer ? sock_ntoa ( peer ) : "<none>" ), sequence );
54  if ( rc != 0 )
55  printf ( ": %s", strerror ( rc ) );
56  printf ( "\n" );
57 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * sock_ntoa(struct sockaddr *sa)
Transcribe socket address.
Definition: socket.c:42
uint32_t len
Length.
Definition: ena.h:14

References len, printf(), rc, sock_ntoa(), and strerror().

Referenced by ping().

◆ ping()

int ping ( const char *  hostname,
unsigned long  timeout,
size_t  len,
unsigned int  count,
int  quiet 
)

Ping a host.

Parameters
hostnameHostname
timeoutTimeout between pings, in ticks
lenPayload length
countNumber of packets to send (or zero for no limit)
quietInhibit output
Return values
rcReturn status code

Definition at line 69 of file pingmgmt.c.

70  {
71  int rc;
72 
73  /* Create pinger */
74  if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, count,
75  ( quiet ? NULL : ping_callback ) ) ) != 0 ){
76  printf ( "Could not start ping: %s\n", strerror ( rc ) );
77  return rc;
78  }
79 
80  /* Wait for ping to complete */
81  if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
82  if ( ! quiet )
83  printf ( "Finished: %s\n", strerror ( rc ) );
84  return rc;
85  }
86 
87  return 0;
88 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int monojob_wait(const char *string, unsigned long timeout)
Wait for single foreground job to complete.
Definition: monojob.c:81
int create_pinger(struct interface *job, const char *hostname, unsigned long timeout, size_t len, unsigned int count, void(*callback)(struct sockaddr *src, unsigned int sequence, size_t len, int rc))
Create pinger.
Definition: pinger.c:312
struct interface monojob
Definition: monojob.c:56
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t len
Length.
Definition: ena.h:14
uint16_t count
Number of entries.
Definition: ena.h:22
void timeout(int)
static void ping_callback(struct sockaddr *peer, unsigned int sequence, size_t len, int rc)
Display ping result.
Definition: pingmgmt.c:48
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References count, create_pinger(), len, monojob, monojob_wait(), NULL, ping_callback(), printf(), rc, strerror(), and timeout().

Referenced by ping_close(), ping_deliver(), ping_demux(), ping_exec(), ping_open(), and ping_rx().