aboutsummaryrefslogtreecommitdiffstats
path: root/pingu_burst.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-07-07 15:52:36 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2011-07-07 15:52:36 +0200
commitddaec4213af40ca933b287d78c93adf0019f8570 (patch)
treeab50e5039b3e7e25f9a65f072dd8ad58d695a4c3 /pingu_burst.c
parente8c3caa9a966ba0889170529aa428e7d0d43184d (diff)
downloadpingu-ddaec4213af40ca933b287d78c93adf0019f8570.tar.bz2
pingu-ddaec4213af40ca933b287d78c93adf0019f8570.tar.xz
pingu_burst: initial implementation
Diffstat (limited to 'pingu_burst.c')
-rw-r--r--pingu_burst.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/pingu_burst.c b/pingu_burst.c
new file mode 100644
index 0000000..f86249a
--- /dev/null
+++ b/pingu_burst.c
@@ -0,0 +1,55 @@
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <netdb.h>
+#include <string.h>
+
+#include <ev.h>
+
+#include "log.h"
+#include "pingu_burst.h"
+#include "pingu_host.h"
+#include "pingu_ping.h"
+
+void ping_burst_start(struct ev_loop *loop, struct pingu_host *host)
+{
+ struct addrinfo hints;
+ struct addrinfo *ai, *rp;
+ int r;
+
+ host->burst.active = 1;
+ host->burst.pings_sent = 0;
+ host->burst.pings_replied = 0;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ r = getaddrinfo(host->host, NULL, &hints, &ai);
+ if (r < 0) {
+ log_error("getaddrinfo(%s): %s", host->host, gai_strerror(r));
+ return;
+ }
+
+ for (rp = ai; rp != NULL; rp = rp->ai_next) {
+ host->burst.saddr = *ai->ai_addr;
+ r = pingu_ping_send(loop, host);
+ if (r >= 0)
+ break;
+ }
+
+ if (rp == NULL)
+ host->burst.active = 0;
+
+}
+
+void pingu_burst_timeout_cb(struct ev_loop *loop, struct ev_timer *w,
+ int revents)
+{
+ struct pingu_host *host = container_of(w, struct pingu_host, burst_timeout_watcher);
+
+ if (host->burst.active) {
+ log_warning("%s: burst already active");
+ return;
+ }
+ log_debug("%s: new burst", host->host);
+ ping_burst_start(loop, host);
+}