+ syslog(LOG_INFO, "Connection is down");
+ }
+
+ if(trigger_cmd && tv.tv_sec>last_receive+next_trigger)
+ {
+ if(no_daemon)
+ printf("Running %s\n", trigger_cmd);
+ else
+ syslog(LOG_INFO, "Running %s", trigger_cmd);
+ child_pid = run_command(trigger_cmd);
+ next_trigger += trigger_interval;
+ }
+ }
+ else if(!connection_status)
+ {
+ unsigned duration = tv.tv_sec-connection_down_time;
+ connection_status = 1;
+ if(no_daemon)
+ printf("Connection is up (was down for %d seconds)\n", duration);
+ else
+ syslog(LOG_INFO, "Connection is up (was down for %d seconds)", duration);
+
+ next_trigger = trigger_delay;
+ }
+
+ if(ping_target)
+ {
+ /* Send ping packets to monitor packet loss */
+ if(tv.tv_sec>=next_ping)
+ {
+ if(pending)
+ {
+ ++lost;
+ if(verbose)
+ printf("Lost ping\n");
+ }
+
+ send_ping(ping_target, seq);
+ pending = seq++;
+ if(!seq)
+ ++seq;
+ ++ping_count;
+ next_ping = tv.tv_sec+1;
+ }
+
+ if(tv.tv_sec>=next_stats)
+ {
+ if(lost)
+ {
+ float loss_ratio = (float)lost/ping_count;
+ if(no_daemon)
+ printf("Packet loss: %.2f%%\n", loss_ratio*100);
+ else
+ syslog(LOG_INFO, "Packet loss: %.2f%%", loss_ratio*100);
+
+ ping_count = 0;
+ lost = 0;
+ }
+
+ next_stats = tv.tv_sec+stats_interval;