+} /* }}} void time_calc */
+
+static int print_header (pingobj_t *ping) /* {{{ */
+{
+ pingobj_iter_t *iter;
+ int i;
+
+#if USE_NCURSES
+ initscr ();
+ cbreak ();
+ noecho ();
+#endif
+
+ i = 0;
+ for (iter = ping_iterator_get (ping);
+ iter != NULL;
+ iter = ping_iterator_next (iter))
+ {
+ ping_context_t *context;
+ size_t buffer_size;
+
+ context = context_create ();
+
+ buffer_size = sizeof (context->host);
+ ping_iterator_get_info (iter, PING_INFO_HOSTNAME, context->host, &buffer_size);
+
+ buffer_size = sizeof (context->addr);
+ ping_iterator_get_info (iter, PING_INFO_ADDRESS, context->addr, &buffer_size);
+
+ buffer_size = 0;
+ ping_iterator_get_info (iter, PING_INFO_DATA, NULL, &buffer_size);
+
+#if USE_NCURSES
+ context->window = newwin (/* height = */ 4, COLS,
+ /* start y = */ 4*i, /* start x = */ 0);
+ box (context->window, 0, 0);
+ mvwprintw (context->window, /* y = */ 0, /* x = */ 5,
+ " %s ping statistics ",
+ context->host);
+ wrefresh (context->window);
+#else /* !USE_NCURSES */
+ printf ("PING %s (%s) %zu bytes of data.\n",
+ context->host, context->addr, buffer_size);
+#endif
+
+ ping_iterator_set_context (iter, (void *) context);
+
+ i++;
+ }
+
+#if USE_NCURSES
+ delwin (main_win);
+ main_win = newwin (LINES - 4*i, COLS, 4*i, 0);
+ scrollok (main_win, TRUE);
+#endif
+
+ return (0);
+} /* }}} int print_header */
+
+static int print_footer (pingobj_t *ping)
+{
+ pingobj_iter_t *iter;
+
+#if USE_NCURSES
+ endwin ();
+#endif
+
+ for (iter = ping_iterator_get (ping);
+ iter != NULL;
+ iter = ping_iterator_next (iter))
+ {
+ ping_context_t *context;
+
+ context = ping_iterator_get_context (iter);
+
+ printf ("\n--- %s ping statistics ---\n"
+ "%i packets transmitted, %i received, %.2f%% packet loss, time %.1fms\n",
+ context->host, context->req_sent, context->req_rcvd,
+ 100.0 * (context->req_sent - context->req_rcvd) / ((double) context->req_sent),
+ context->latency_total);
+
+ if (context->req_rcvd != 0)
+ {
+ double num_total;
+ double average;
+ double deviation;
+
+ num_total = (double) context->req_rcvd;
+
+ average = context->latency_total / num_total;
+ deviation = sqrt (((num_total * context->latency_total_square) - (context->latency_total * context->latency_total))
+ / (num_total * (num_total - 1.0)));
+
+ printf ("rtt min/avg/max/sdev = %.3f/%.3f/%.3f/%.3f ms\n",
+ context->latency_min,
+ average,
+ context->latency_max,
+ deviation);
+ }
+
+ ping_iterator_set_context (iter, NULL);
+ context_destroy (context);
+ }