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.
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 ( GPL2_OR_LATER_OR_UBDL  )
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.

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

Referenced by ping().

                                                 {

        /* Display ping response */
        printf ( "%zd bytes from %s: seq=%d",
                 len, ( peer ? sock_ntoa ( peer ) : "<none>" ), sequence );
        if ( rc != 0 )
                printf ( ": %s", strerror ( rc ) );
        printf ( "\n" );
}
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.

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

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

                                           {
        int rc;

        /* Create pinger */
        if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, count,
                                    ( quiet ? NULL : ping_callback ) ) ) != 0 ){
                printf ( "Could not start ping: %s\n", strerror ( rc ) );
                return rc;
        }

        /* Wait for ping to complete */
        if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) {
                if ( ! quiet )
                        printf ( "Finished: %s\n", strerror ( rc ) );
                return rc;
        }

        return 0;
}