iPXE
pinger.h File Reference

ICMP ping sender. More...

#include <stdint.h>
#include <ipxe/interface.h>
#include <ipxe/socket.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int create_pinger (struct interface *job, const char *hostname, unsigned long timeout, size_t len, unsigned int count, void(*callback)(struct sockaddr *peer, unsigned int sequence, size_t len, int rc))
 Create pinger.

Detailed Description

ICMP ping sender.

Definition in file pinger.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

References count, len, peer, rc, and timeout().

◆ create_pinger()

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) )
extern

Create pinger.

Parameters
jobJob control interface
hostnameHostname to ping
timeoutTimeout (in ticks)
lenPayload length
countNumber of packets to send (or zero for no limit)
callbackCallback function (or NULL)
Return values
rcReturn status code

Definition at line 313 of file pinger.c.

317 {
318 struct pinger *pinger;
319 int rc;
320
321 /* Sanity check */
322 if ( ! timeout )
323 return -EINVAL;
324
325 /* Allocate and initialise structure */
326 pinger = zalloc ( sizeof ( *pinger ) );
327 if ( ! pinger )
328 return -ENOMEM;
329 ref_init ( &pinger->refcnt, NULL );
332 timer_init ( &pinger->timer, pinger_expired, &pinger->refcnt );
334 pinger->len = len;
335 pinger->remaining = ( count ? ( count + 1 /* Initial packet */ ) : 0 );
337 pinger->rc = -ETIMEDOUT;
338
339 /* Open socket */
341 hostname, NULL ) ) != 0 ) {
342 DBGC ( pinger, "PINGER %p could not open socket: %s\n",
343 pinger, strerror ( rc ) );
344 goto err;
345 }
346
347 /* Attach parent interface, mortalise self, and return */
349 ref_put ( &pinger->refcnt );
350 return 0;
351
352 err:
354 ref_put ( &pinger->refcnt );
355 return rc;
356}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
void timeout(int)
ring len
Length.
Definition dwmac.h:226
#define SOCK_ECHO
Definition socket.h:35
#define DBGC(...)
Definition compiler.h:505
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670
#define ENOMEM
Not enough space.
Definition errno.h:535
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
static struct interface_descriptor pinger_xfer_desc
Pinger data transfer interface descriptor.
Definition pinger.c:290
static void pinger_close(struct pinger *pinger, int rc)
Close pinger.
Definition pinger.c:135
static struct interface_descriptor pinger_job_desc
Pinger job control interface descriptor.
Definition pinger.c:299
static void pinger_expired(struct retry_timer *timer, int over __unused)
Handle timer expiry.
Definition pinger.c:167
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
int xfer_open_named_socket(struct interface *xfer, int semantics, struct sockaddr *peer, const char *name, struct sockaddr *local)
Open named socket.
Definition resolv.c:403
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A pinger.
Definition pinger.c:58
unsigned int remaining
Number of remaining expiry events (zero to continue indefinitely)
Definition pinger.c:79
struct interface job
Job control interface.
Definition pinger.c:63
struct retry_timer timer
Timer.
Definition pinger.c:68
unsigned long timeout
Timeout.
Definition pinger.c:70
void(* callback)(struct sockaddr *src, unsigned int sequence, size_t len, int rc)
Callback function.
Definition pinger.c:90
size_t len
Payload length.
Definition pinger.c:73
int rc
Return status.
Definition pinger.c:81
struct refcnt refcnt
Reference count.
Definition pinger.c:60
struct interface xfer
Data transfer interface.
Definition pinger.c:65

References pinger::callback, count, DBGC, EINVAL, ENOMEM, ETIMEDOUT, intf_init(), intf_plug_plug(), pinger::job, len, pinger::len, NULL, pinger_close(), pinger_expired(), pinger_job_desc, pinger_xfer_desc, pinger::rc, rc, ref_init, ref_put, pinger::refcnt, pinger::remaining, SOCK_ECHO, src, strerror(), pinger::timeout, timeout(), pinger::timer, pinger::xfer, xfer_open_named_socket(), and zalloc().

Referenced by ping().