iPXE
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)
 FILE_SECBOOT (PERMITTED)
static void ping_callback (struct sockaddr *peer, unsigned int sequence, size_t len, int rc)
 Display ping result.
int ping (const char *hostname, unsigned long timeout, size_t len, unsigned int count, int quiet)
 Ping a host.

Detailed Description

ICMP ping management.

Definition in file pingmgmt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ping_callback()

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 49 of file pingmgmt.c.

50 {
51
52 /* Display ping response */
53 printf ( "%zd bytes from %s: seq=%d",
54 len, ( peer ? sock_ntoa ( peer ) : "<none>" ), sequence );
55 if ( rc != 0 )
56 printf ( ": %s", strerror ( rc ) );
57 printf ( "\n" );
58}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
ring len
Length.
Definition dwmac.h:226
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:1
const char * sock_ntoa(struct sockaddr *sa)
Transcribe socket address.
Definition socket.c:43
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References len, peer, 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 70 of file pingmgmt.c.

71 {
72 int rc;
73
74 /* Create pinger */
75 if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, count,
76 ( quiet ? NULL : ping_callback ) ) ) != 0 ){
77 printf ( "Could not start ping: %s\n", strerror ( rc ) );
78 return rc;
79 }
80
81 /* Wait for ping to complete */
82 if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
83 if ( ! quiet )
84 printf ( "Finished: %s\n", strerror ( rc ) );
85 return rc;
86 }
87
88 return 0;
89}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
void timeout(int)
static unsigned int count
Number of entries.
Definition dwmac.h:220
struct interface monojob
Definition monojob.c:57
int monojob_wait(const char *string, unsigned long timeout)
Wait for single foreground job to complete.
Definition monojob.c:82
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:313
static void ping_callback(struct sockaddr *peer, unsigned int sequence, size_t len, int rc)
Display ping result.
Definition pingmgmt.c:49

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

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